steventnorris
steventnorris

Reputation: 5896

Span Id changes in ASP.NET

I have a span in a .master page that uses runat="server". Server-side, c# code adds to the innerHtml of this span. The span is id="tickerfade"; however, when it is rendered on the page the id is changed to id=ctl00_tickerfade. why does this happen and how can I stop it?

Upvotes: 1

Views: 1432

Answers (2)

Harry89pl
Harry89pl

Reputation: 2435

It's happend because Control which is rendered on server side has autogenerated Client side Id.

If you'll use asp.net out of box control (<asp:Label />and so on) you can set ClientIdMode to Static

if you want to use this span in javascript you can write

$('<%= tickerfade.ClientID %>).click(....)

Upvotes: 1

Tim Schmelter
Tim Schmelter

Reputation: 460158

You can set the control's ClientIdMode to Static.

The ClientID value is set to the value of the ID property. If the control is a naming container, the control is used as the top of the hierarchy of naming containers for any controls that it contains.

Have a look at following link for further informations on ASP.NET Web Server Control Identification:

http://msdn.microsoft.com/en-us/library/1d04y8ss.aspx

If the real problem is how to find the correct id on clientside, you can use the ClientId property.

Upvotes: 4

Related Questions