control id change automatically in MasterPage
why id of control changed automatically when we use it in masterpage , while in simple page it does not change??
this is source code after run the MasterPage
as :: <input name="ctl00$cp1$txtUName" type="text" id="ctl00_cp1_txtUName" style="width:128px;" />
this is source code after run Simple Page
AS:<input na开发者_JS百科me="txtUName" type="text" id="txtUName" />
these are same controls
That is not true, when you use input control with runat="server" it's id will be generated by server. If you are using asp.net 4.0 then you can use CliendIDMode="static"
in <% @page ...
declaration to prevent it.
I'm guessing this problem has arisen from some javascript you're using which no longer references the correct ID (because its changed). If so when you send your javascript from the server use the clientID method. So for example alert('<%= txtUName.ClientID %>')
will generate an alertbox with the correct ID contained at runtime
I guess that you have used a TextboxControl in your master page and that what your showing in your question is the resulting HTML.
The master page is a naming container (it's really a user control that gets injected in the page's control hierarchy). All the children of a naming container gets the containers name as prefix in order to disambiguate the control name from controls with the same name inside another container.
精彩评论