Java Script in Web Content

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.
 
M

Munna

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
 
E

Eliyahu Goldin

For your page, make a method FindControlById that will accept control ID and
find the dynamically added control on the page. Then use something like:

document.getElementByID("<%= FindControlById("M001").ClientID =>")


--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
B

bruce barker

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)
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top