Reference a TextBox on a user control

H

Henke

Hi!
How do I reference let's say a button from a javascript on a user control?
The name of the button is testButton, and I've tried testButton.click() but
I get buttonTest is undefined.

Thanks!
/Henke
 
S

Scott Allen

When you biuld the javascript on the server side use the textButton
object's ClientID property. If you 'view source' on the page in the
browser you'll see the control has been given a prefix to make sure it
is unique.
 
H

Henke

Thanks for your answer!

That looks quite uggly to me. If I move the UserControl to an other WebForm,
it wouldn't be given the same name and then the javascript wouldn't work.

/Henke
 
S

Scott Allen

Hi Henke:

That's right - if the control moves around the ID could change.

The best way to approach this is to build the JavaScript dynamically
in your C#/VB code behind file with the ClientID property before
sending it to the client.
 
H

Henke

That's an idea, thank you!

/Henke

Scott Allen said:
Hi Henke:

That's right - if the control moves around the ID could change.

The best way to approach this is to build the JavaScript dynamically
in your C#/VB code behind file with the ClientID property before
sending it to the client.
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top