Javascrpt and User Controls. Help!

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I'm trying to change a links href with javascript. I know that asp.net will
change the controls ids to protect against multiple controls on a page. So I
use the following code.

var buttonId = <%= this.FindControl("imgLinkRead").ClientID %>;

The problem is that imgLinkRead is a user control, so it is a control within
a control. If I look at the source the id imgLinkRead is
'Features1_imgLinkRead_imageLink'. How to I get that from javascript? I
need help ASAP. Thanks
 
The same way Bind in Javascript
or
Inject your custom made Javascript to browser.

you already have it.
 
The FindControl method operates on the immediate children of the Control you
specify. If you want the ClientID of a Control inside the UserControl, you
have to call FindControl on the UserControl. Example:

((UserControlName)this.FindControl("imgLinkRead")).FindControl("SomeControl").ClientID

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
 
Thank you for the reply. If I try this code

var clientId = <%=
((ImageButtonLink)this.FindControl("imgLinkRead")).FindControl("imageLink").ClientID %>;

ImageButtonLink being the control and imageLink being the hyperlink within
the ImageButtonLink, clientId returns the NavigationUrl. Why would it do
that? Thanks again.
 
Hi eric,
var clientId = <%=
((ImageButtonLink)this.FindControl("imgLinkRead")).FindControl("imageLink").ClientID
%>;

ImageButtonLink being the control and imageLink being the hyperlink within
the ImageButtonLink, clientId returns the NavigationUrl. Why would it do
that? Thanks again.

I couldn't say without seeing the actual code.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
 
Back
Top