473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Javascrpt and User Controls. Help!

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
Nov 8 '07 #1
5 934
LVP
The same way Bind in Javascript
or
Inject your custom made Javascript to browser.

you already have it.
"eric" <er**@discussions.microsoft.comwrote in message
news:36**********************************@microsof t.com...
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

Nov 8 '07 #2
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" <er**@discussions.microsoft.comwrote in message
news:36**********************************@microsof t.com...
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


Nov 8 '07 #3
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" <er**@discussions.microsoft.comwrote in message
news:36**********************************@microsof t.com...
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

Nov 8 '07 #4
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" <er**@discussions.microsoft.comwrote in message
news:36**********************************@microsof t.com...
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


Nov 8 '07 #5
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" <er**@discussions.microsoft.comwrote in message
news:6F**********************************@microsof t.com...
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" <er**@discussions.microsoft.comwrote in message
news:36**********************************@microso ft.com...
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



Nov 9 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Robert Howells | last post by:
Perhaps I'm just too new at this to pull it off, or perhaps it's just bad architecture. I'd appreciate some feedback on the the wisdom (or lack thereof) in attempting the following: I'm not new...
4
by: John | last post by:
Hi all, I have posted this type of question quite a few times but to date, no-one has actually been able to provide me with a solution. I really need to understand how to do this properly. My...
5
by: mytestemailaccount | last post by:
Hi, Hope you can help. I am relatively new to all this but would appreciate the groups help. The scenario: I am c# and asp.net to create a web application. The web page contains a user...
4
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
2
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
0
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
3
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
9
by: Gummy | last post by:
Hello, I created a user control that has a ListBox and a RadioButtonList (and other stuff). The idea is that I put the user control on the ASPX page multiple times and each user control will...
0
by: jburnage | last post by:
I need help in getting the values from a dynamically added user control when a user submits a form. The controls are added to a placeholder and this all works fine - but its looping through the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.