Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Javascrpt and User Controls. Help!

Reply
Thread Tools

Javascrpt and User Controls. Help!

 
 
=?Utf-8?B?ZXJpYw==?=
Guest
Posts: n/a
 
      11-08-2007
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
 
Reply With Quote
 
 
 
 
LVP
Guest
Posts: n/a
 
      11-08-2007
The same way Bind in Javascript
or
Inject your custom made Javascript to browser.

you already have it.


"eric" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
 
=?Utf-8?B?ZXJpYw==?=
Guest
Posts: n/a
 
      11-08-2007
But it doesn't work. For some reason the ClientId doesn't return correct id.

"LVP" wrote:

> The same way Bind in Javascript
> or
> Inject your custom made Javascript to browser.
>
> you already have it.
>
>
> "eric" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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

>
>
>

 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      11-08-2007
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

"eric" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
=?Utf-8?B?ZXJpYw==?=
Guest
Posts: n/a
 
      11-08-2007
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.

"Kevin Spencer" wrote:

> 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
>
> "eric" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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

>
>
>

 
Reply With Quote
 
JinWeiJie@gmail.com
Guest
Posts: n/a
 
      11-09-2007
hi,

var objA = document.getElementById('<%= this.imgLinkRead.ClientID
%>');
objA.href = "www.someUrl.com";

hope this can help.

eric wrote:
> 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


 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      11-09-2007
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

"eric" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>
> "Kevin Spencer" wrote:
>
>> 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
>>
>> "eric" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > 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

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
insert javascrpt into textarea? globalrev Javascript 15 05-12-2008 12:03 PM
How to run a javascrpt function from the server? Rob Meade ASP .Net 7 03-18-2007 09:13 AM
javascrpt IDE Grzegorz Ślusarek Javascript 3 05-20-2006 02:29 PM
Hi I have one web application and i want to get the number of users who are currently accessing the application. Also I want to get the user details of each user, which is stored in a database. How can I do this? Pls help. Getting No: and anu Java 11 05-12-2005 03:25 PM
Where is "official", not Microsoft, spec for javascrpt, etc.? Howard Kaikow Javascript 4 10-12-2004 10:47 AM



Advertisments