I have a e-mail subscription user control. When using in different page it is generating different id/name. I'm not sure why it is doing that. Event if the two page is under one masterpage.
The Id of a usercontrol is dynamic and based on the parentId(s) and the id of the usercontrol itself. Don't assume this id is always the same. This is the way Asp.net works. What do you want to achieve?
Just for your information: if you want to access a server-side user control from client-side code, you can also use the "ClientID" property of your server side control. This will give you the actual ID of your control at the client side, depending of its parents etc. like Richard mentioned.
True but you still can't use it in an extenal Javascript file using JQuery. @Sherry, Could be a lot of things causing that. But by default Asp.Net is generating id's for you so better to use Classes instead of id's to ensure you don't run into issues.
user control is generating different id
Hi,
I have a e-mail subscription user control. When using in different page it is generating different id/name. I'm not sure why it is doing that. Event if the two page is under one masterpage.
Hi Sherry
Could you perhaps share some of the code for the user control?
/Jan
Hi Sherry,
The Id of a usercontrol is dynamic and based on the parentId(s) and the id of the usercontrol itself. Don't assume this id is always the same. This is the way Asp.net works. What do you want to achieve?
Cheers,
Richard
Hey guys,
I just used a class instead to access the control using jquery. I was just wondering why i'm not encountering same issue with my other control.
Thanks though. :D
Hi Sherry,
Just for your information: if you want to access a server-side user control from client-side code, you can also use the "ClientID" property of your server side control. This will give you the actual ID of your control at the client side, depending of its parents etc. like Richard mentioned.
Cheers,
Michael.
True but you still can't use it in an extenal Javascript file using JQuery. @Sherry, Could be a lot of things causing that. But by default Asp.Net is generating id's for you so better to use Classes instead of id's to ensure you don't run into issues.
Cheers,
Richard
Hi Richard and Sherry
@Richard: In ASP.NET 4 it should be possible to generate a clean id for the HTML, right? I just can't seem to remember the setting at the moment.
But if one is using 3.5 then classes are the way forward.
Just a thought.
Cheers
/Jan
@Jan,
Yes true, but not everyone is using 4.0
Hi,
In Asp.Net 4 I think you can use the ClientIDMode property to specify how the client ID must be generated. Using the "static" value uses the value of the ID attribute: http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientidmode.aspx
Cheers,
Michael.
Hi
@Richard, true - but just thought it's worth mentioning for future reference if others have a look at this post if they have the same issue :-)
/Jan
is working on a reply...