Accessing HTML Control in ASCX through JavaScript

Discussion in 'ASP .Net' started by George Durzi, Dec 19, 2003.

  1. George Durzi

    George Durzi Guest

    I have a JavaScript called common.js that is referenced by every ASPX in my
    web application. In common.js, I have a funtion called findText (which I use
    to help me navigate through drop down lists by typing the first few letters
    of an item in the drop down list).

    So this is how I would use it:

    <input type="text" id="searchCompany" size="1" name="searchCompany"
    onkeyup="findText(this, Company);">
    <asp:dropdownlist ID="Company" Runat="server"></asp:dropdownlist>

    All this is fine on a normal webform. But I run into trouble when my
    dropdown list is inside a user control. Consider this pseudo HTML (as it
    would look like after the page was rendered)

    <html>
    <head>
    <script src='http://localhost/mywebapp/js/common.js'
    language='JavaScript'></script>
    </head>
    <form id="frmMain" runat="server">
    <McAddEditAscx User Control Rendered>
    <input type="text" id="searchCompany" size="1"
    name="searchCompany" onkeyup="base.findText(this, Company);">
    <select name="_McAddEditAscx:Company"
    id="_McAddEditAscx_Company">
    <option value="something">something</option>
    ...
    </select>
    </McAddEditAscx User Control Rendered>
    </form>
    </html>


    Notice that when the UserControl got rendered my dropdownlist with
    id="Company" was rendered as _McAddEditAscx:Company

    I tried fugding my searchCompany box by doing

    <input type="text" id="searchCompany" size="1" name="searchCompany"
    onkeyup="base.findText(this, _McAddEditAscx:Company);">

    I don't that's a clean solution though.

    So how do I access HTML controls that are in a user control using
    JavaScript?

    THANK YOU!!
    George Durzi, Dec 19, 2003
    #1
    1. Advertising

  2. You can either output the unique id of those controls in your server side
    code (which will include the name decoration), or you can iterate through
    the controls looking at substrings for the text that you want.

    --
    Chris Jackson
    Software Engineer
    Microsoft MVP - Windows Client
    Windows XP Associate Expert
    --
    More people read the newsgroups than read my email.
    Reply to the newsgroup for a faster response.
    (Control-G using Outlook Express)
    --

    "George Durzi" <> wrote in message
    news:...
    > I have a JavaScript called common.js that is referenced by every ASPX in

    my
    > web application. In common.js, I have a funtion called findText (which I

    use
    > to help me navigate through drop down lists by typing the first few

    letters
    > of an item in the drop down list).
    >
    > So this is how I would use it:
    >
    > <input type="text" id="searchCompany" size="1" name="searchCompany"
    > onkeyup="findText(this, Company);">
    > <asp:dropdownlist ID="Company" Runat="server"></asp:dropdownlist>
    >
    > All this is fine on a normal webform. But I run into trouble when my
    > dropdown list is inside a user control. Consider this pseudo HTML (as it
    > would look like after the page was rendered)
    >
    > <html>
    > <head>
    > <script src='http://localhost/mywebapp/js/common.js'
    > language='JavaScript'></script>
    > </head>
    > <form id="frmMain" runat="server">
    > <McAddEditAscx User Control Rendered>
    > <input type="text" id="searchCompany" size="1"
    > name="searchCompany" onkeyup="base.findText(this, Company);">
    > <select name="_McAddEditAscx:Company"
    > id="_McAddEditAscx_Company">
    > <option value="something">something</option>
    > ...
    > </select>
    > </McAddEditAscx User Control Rendered>
    > </form>
    > </html>
    >
    >
    > Notice that when the UserControl got rendered my dropdownlist with
    > id="Company" was rendered as _McAddEditAscx:Company
    >
    > I tried fugding my searchCompany box by doing
    >
    > <input type="text" id="searchCompany" size="1" name="searchCompany"
    > onkeyup="base.findText(this, _McAddEditAscx:Company);">
    >
    > I don't that's a clean solution though.
    >
    > So how do I access HTML controls that are in a user control using
    > JavaScript?
    >
    > THANK YOU!!
    >
    >
    >
    Chris Jackson, Dec 19, 2003
    #2
    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. Quentin
    Replies:
    1
    Views:
    468
    Quentin
    Jul 29, 2003
  2. Jason Shohet
    Replies:
    1
    Views:
    462
    Kevin Spencer
    Nov 10, 2003
  3. Holger (David) Wagner
    Replies:
    2
    Views:
    1,915
    Holger (David) Wagner
    Jul 3, 2004
  4. Joe
    Replies:
    1
    Views:
    352
    Jeffrey Tan[MSFT]
    Feb 16, 2004
  5. Replies:
    2
    Views:
    520
Loading...

Share This Page