Script Control.value method

Discussion in 'ASP .Net Web Controls' started by john, Nov 2, 2007.

  1. john

    john Guest

    I read that this method:



    <script type="text/javascript" language="javascript">

    alert($get('<%= CheckTxt.ClientID%>').value)

    </script>



    Can be used instead of:



    alert(document.getElementById("TabContainer1_TabPanel5_FormView8_CheckTxt").value)





    But I receive a CheckTxt not Declared error, any suggestion as to how to
    implement this?



    Thanks

    John
    john, Nov 2, 2007
    #1
    1. Advertising

  2. Hi John,

    The purpose of using <%= CheckTxt.ClientID %> is to output a dynamic id of
    the control CheckTxt at run-time. To make ASP.NET compiler recognize
    CheckTxt, you must have a control with ID "CheckTxt" at the direct child
    control hierarchy of current container (Page class or UserControl according
    to the context).

    If you're having other INamingContainer between this control and the root
    container (for example, you're defining a control with id "CheckTxt" within
    an ITemplate such as ItemTemplate), the compiler will not be able to refer
    to the control directly using reference "CheckTxt".

    You can use ClientScript.RegisterStartupScript or RegisterScriptBlock to
    generate the javascript functions at run-time; at that time if you could
    get a reference to a control (using FindControl), then you can use its
    ClientID property to build the javascript.

    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Nov 5, 2007
    #2
    1. Advertising

  3. john

    john Guest

    Thanks, I was doing some experimenting and was thinking maybe it was just as
    you stated, because if I just added a label control if found it no problem;
    so it's the template that is at issue. I will study your other method to see
    if I can learn it, I don't like having to rewrite my script with every
    design change, so that would be a plus if I can do it your way.

    John
    ""Walter Wang [MSFT]"" <> wrote in message
    news:...
    > Hi John,
    >
    > The purpose of using <%= CheckTxt.ClientID %> is to output a dynamic id of
    > the control CheckTxt at run-time. To make ASP.NET compiler recognize
    > CheckTxt, you must have a control with ID "CheckTxt" at the direct child
    > control hierarchy of current container (Page class or UserControl
    > according
    > to the context).
    >
    > If you're having other INamingContainer between this control and the root
    > container (for example, you're defining a control with id "CheckTxt"
    > within
    > an ITemplate such as ItemTemplate), the compiler will not be able to refer
    > to the control directly using reference "CheckTxt".
    >
    > You can use ClientScript.RegisterStartupScript or RegisterScriptBlock to
    > generate the javascript functions at run-time; at that time if you could
    > get a reference to a control (using FindControl), then you can use its
    > ClientID property to build the javascript.
    >
    > Regards,
    > Walter Wang (, remove 'online.')
    > Microsoft Online Community Support
    >
    > ==================================================
    > When responding to posts, please "Reply to Group" via your newsreader so
    > that others may learn and benefit from your issue.
    > ==================================================
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >
    john, Nov 5, 2007
    #3
    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. Replies:
    3
    Views:
    310
    Chris Uppal
    Mar 10, 2006
  2. Rajat
    Replies:
    3
    Views:
    677
    Jorgen Grahn
    Jan 8, 2010
  3. VYAS ASHISH M-NTB837
    Replies:
    2
    Views:
    539
    Jan Kaliszewski
    Jan 7, 2010
  4. Robert Cohen
    Replies:
    3
    Views:
    248
    Andrew Durstewitz
    Jul 15, 2003
  5. Kyung won Cheon
    Replies:
    0
    Views:
    182
    Kyung won Cheon
    Nov 21, 2008
Loading...

Share This Page