ajax and asp.net in user control

O

olivier

Hi,

I want to use javascript (ajax) in User Control but to call
the object is difficult.

If my user control is called MyControl.
To use the object in javascript, i make,

Ex:
document.GetElementId("MyControl_textbox").value

Have you an idea to get the name of the user control asp.net
to instance my code javascript cause the same code javascript must to work
in other User control.

Thank's
Olivier
ps : excuse me for my poor english.
 
L

Laurent Bugnion [MVP]

Salut,
*Hi,*
**
*I want to use javascript (ajax) in User Control but to call*
*the object is difficult.*
**
*If my user control *is called MyControl.
*To use the object in javascript, i make,*
**
*Ex:*
*document.GetElementId("MyControl_textbox").value*
**
*Have you an idea to get the name of the user control asp.net*
*to instance my code javascript cause the same code javascript must to work*
*in other User control.*
**
*Thank's*
*Olivier*
*ps : excuse me for my poor english.*

Je ne suis pas sûr d'avoir tout compris, si tu veux tu peux demander en
français.

Dans ton "code-behind", tu peux obtenir l'ID du widget que tu veux
adresser en JavaScript en utilisant la propriété "ClientID". Comme cette
ID dépend de la position (hierarchie) de ton User control dans la page,
c'est le seul moyen fiable!!

Par exemple:

string startUpScript = "<script type='text/javascript'>"
+ "document.getElementById('"
+ myTextBox.ClientID
+ "').value = 'Hello world';"
+ "</script>";

this.Page.ClientScript.RegisterStartupScript( this.Page.GetType(),
"startUpScript", startUpScript );

HTH,
Laurent
 

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,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top