Why do webcontol ID's change

G

Guest

I have a lable control in a repeater and 2 link buttons. The lable is named
lblCurrentPage and the link buttons are named "Prev" and "Next". Once the
page is uploaded and viewed through the browser, all three button id's
change. Why is this? I see it has been changed by looking at the source of
the web page. I thnk this may be causing a problem in my code because I'm
refrencing the controls by the id name I gave them. Is there a way to keep
these controls from being renamed?
 
G

Guest

It seems you are trying to access your controls from client side. to be able
to do so, use ClientID property of your server control to access the client
reference.
you client code might contain something similar to this
var value = document.getElementById("<%=txtBx.ClientID%>").value
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
MCPD: .Net 2.0 Enterprise Application Developer
 
G

Guest

Muhammad,
thank you for your help. I didn't even think about that. As a workaround I
just took the controls out of the repeater and referenced them in the code
behind the normal way: thecontolname.text

Thanks again. I'll know next time what to do right away.
 
C

clintonG

// Make a note that the ClientID property is useless when trying to
reference
// DataList list items required to be used in the SideBar of the 2.0 Wizard.
// Each list item's ClientID value is named "SideBarButton" as shown...
_SideBarList_ctl01_SideBarButton.

// When the DataList has three list items the control tree will look like
this...
_SideBarList_ctl00_SideBarButton.
_SideBarList_ctl01_SideBarButton.
_SideBarList_ctl02_SideBarButton.

// The 2.0 Wizard's DataList requires objects which inherit from
// IButtonControl. The values of these ctl properties are generated by
// the compiler. Any other objects created in the page may and do cause
// different values for the ctl objects each time the page is compiled.
// Thus, referencing the value of ctl is not reliable.
//
// We can however reliably reference the 2.0 Wizard control's
// SideBar DataList list item's Title property that is rendered as
// the title attribute of the HTML anchor. This is the same value
// that is displayed as the ToolTip.

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top