Search code examples
c#asp.netajaxviewstateweb-controls

Could the repetition of Ids cause random errors concerning viewstate?


The asp.net accept repetitive Ids for asp.net server controls in different template fields .

<ItemTemplate>
<asp:HiddenField ID="HDN_MainCode" Value='<%#Eval("v_main_code")%>' runat="server" /> 
</ItemTemplate>

in another grid view :

<ItemTemplate>
<asp:HiddenField ID="HDN_MainCode" Value='<%#Eval("v_main_code")%>' runat="server" /> 
</ItemTemplate>

Could this type of repeating cause random errors concerning viewstate ? and if the answer is yes , How could i detect all the repetition in .aspx document


Solution

  • Could this type of repeating cause random errors concerning viewstate ?

    No. These inner controls gets a unique ID at rendering. For example If you have lable ID ProductIDLabel in your ListView, then its generated ID would be something like:

    ListView1$ctrl0$ProductIDLabel
    ListView1$ctrl1$ProductIDLabel
    

    For more see: ASP.NET Web Server Control Identification

    When the control is inside a data-bound control that creates multiple instances of the control, the value that you assign to the ID property is concatenated with the naming container and with an incrementing index.

    But if you have ClientIDMode set to Static, then you will get the ID same as the one specified in the ASPX page.