Java Script in Web Content

Discussion in 'ASP .Net' started by CKKwan, Jun 8, 2008.

  1. CKKwan

    CKKwan Guest

    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.
     
    CKKwan, Jun 8, 2008
    #1
    1. Advertising

  2. CKKwan

    Munna Guest

    On Jun 8, 7:04 am, CKKwan <> wrote:
    > 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
     
    Munna, Jun 8, 2008
    #2
    1. Advertising

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


    "CKKwan" <> wrote in message
    news:...
    > 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.
     
    Eliyahu Goldin, Jun 8, 2008
    #3
  4. CKKwan

    bruce barker Guest

    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)

    CKKwan wrote:
    > 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.
     
    bruce barker, Jun 8, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hazz
    Replies:
    6
    Views:
    49,949
    SkyUCHC
    Jun 9, 2010
  2. SA
    Replies:
    1
    Views:
    272
    Joe Francia
    Jan 25, 2004
  3. Rajat
    Replies:
    3
    Views:
    730
    Jorgen Grahn
    Jan 8, 2010
  4. VYAS ASHISH M-NTB837
    Replies:
    2
    Views:
    589
    Jan Kaliszewski
    Jan 7, 2010
  5. Blue®
    Replies:
    10
    Views:
    326
    Thomas 'PointedEars' Lahn
    May 27, 2005
Loading...

Share This Page