Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any drawback to set ClientIDMode = Static on every object ( set on maincontent of master page)

I am working on asp.net project and each time i need to use jquery identifier $(#"objectID"). I have to change the ClientIDMode on each object to be static. Since I have noticed that the default client ID mode is Inherit so i set the MainContent Client ID mode to be static and i have found that all the object became static.

This will sure save a lot of time when working with jquery, but i just want to know is there any drawback from this and is there any reason why shouldn't ClientIDMode set to be static at the first place ?

like image 753
Sarawut Positwinyu Avatar asked May 19 '11 10:05

Sarawut Positwinyu


People also ask

What does ClientIDMode static do?

By default all ASP.net controls uses the Inherit as the ClientIDMode. Static Mode: As the name suggests the static mode can be used to give a constant ID to the ASP.net control. Simply assign ClientIDMode property equal to Static in your control and it will start generating the ID using the static mode.

What is ClientId in asp net?

The ClientId is generated by concatenating id of each parent naming container with the id of control. In data binding scenario the control id is prefixed with an incremental value. Each segment is separated by underscore (_) character. <asp:TextBox ID="txtName" runat="server" ClientIDMode="AutoID"></asp:TextBox>


2 Answers

You want to be careful about setting the ClientIDMode to Static for things like user controls, or you could end up with multiple elements with the same ID.

For data-bound controls like GridView, you'll also want to use the ClientIDRowSuffix property in order to ensure each row is differentiated.

This post has some good examples.

like image 117
Graham Clark Avatar answered Oct 12 '22 07:10

Graham Clark


Another way to deal with the IDs in JavaScript would be to do something like this:

var something = '<%= btnId.ClientID %>'; 

Example: If you have a button control like this:

<asp:Button ID="btnId" runat="server"></asp:Button>     

and the ID is translated to id="ct100_ContentPlaceHolder1_btnId" then you could use the variable something to access the control.

like image 40
Krishna Tummalapalli Avatar answered Oct 12 '22 06:10

Krishna Tummalapalli