Reference a TextBox on a user control

  • Thread starter Thread starter Henke
  • Start date Start date
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
 
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.
 
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
 
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.
 
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.
 
Back
Top