Java Script in Web Content

  • Thread starter Thread starter CKKwan
  • Start date Start date
C

CKKwan

Create a Master Page, and a Web Content.

When trying to use Javascript to update the ASP control, we need to
find the control using:

document.getElementByID("<%= IDTag.ClientID =>")

Now the problem is, what if the control is added in dynamically?

I add those controls in Page_Init giving them an ID from M001 until
M050 (or more), and need to update them dynamically using Javascript
from time to time.

Thanks in advance.
 
Create a Master Page, and a Web Content.

When trying to use Javascript to update the ASP control, we need to
find the control using:

document.getElementByID("<%= IDTag.ClientID =>")

Now the problem is, what if the control is added in dynamically?

I add those controls in Page_Init giving them an ID from M001 until
M050 (or more), and need to update them dynamically using Javascript
from time to time.

Thanks in advance.

Hi

As you have already seen when you create the dynamically added
controls initially clientID is not the final clientID in your page..
when we add the dynamically added controls to a container, the
clientid of a control is changed then...

so to get the final client id of the controls you can override the
Prerender page method and get the final client ids

you can add add few generic script to perform your operation and then
call the javascripts
with passing the client id as param to perfrom your operation

Best of luck

Munna
www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com
 
after adding the controls:

Page.ScriptManager.RegisterStartupScript(
this.GetType(),
"IDTag",
string.Format(
"var IDTag = document.getElmentById('{0}');",
IDTag.ClientID),
true);

you then have a javascript variable that references the control.

-- bruce (sqlwork.com)
 
Back
Top