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)

    <script src='http://localhost/mywebapp/js/common.js'
    <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"
    <option value="something">something</option>
    </McAddEditAscx User Control Rendered>

    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

    George Durzi, Dec 19, 2003
    1. Advertisements

  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, Dec 19, 2003
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.