DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: question on how to reference web controls from client-side Javascript .

  1. #1
    Join Date
    Dec 2005

    question on how to reference web controls from client-side Javascript .

    I have some simple Javascript here that needs to reference not only a
    CheckBox object being passed as a parameter, but also various other
    fields on my web page.

    My main question is HOW do I access/manipulate controls with
    client-side script ?

    I know how to access the value of the Checkbox because I pass it to my
    javascript function like this : QuoteConv(this) . However, since Asp
    2.0 renames all the ID properties of my web controls, what's the best
    way to reference all the various controls (i.e. html TextBox, checkbox,
    radio, etc) ???

    Here's the beginning of my aspx page with the client-side javascript :

    <%@ Page Language="C#" ... %>
    <asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <script language="javascript" type="text/javascript">
    function QuoteConv(chk) {

    /* I'M TAKING A GUESS HERE !!! */
    cCurr1 = document.aspnetForm.EditDropDownCur1.value ;
    cCurr2 = document.aspnetForm.EditDropDownCur2.value ;

    if (document.aspnetForm.hidInvert.value == "Off") {
    cQteCur1 = cCurr1;
    cQteCur2 = cCurr2;
    } else {
    cQteCur1 = cCurr2;
    cQteCur2 = cCurr1;
    document.aspnetForm.txtQuoteConv1.value = cQteCur1;
    document.aspnetForm.txtQuoteConv1.value = cQteCur2;

    and some controls on the EditItemTemplate that I need to
    access/manipulate :

    <asp:RadioButtonList ID="radioBuySell" runat="server"
    SelectedValue='<%# Bind("buy_sell")%>'
    <asp:ListItem Value="1">Buy</asp:ListItem>
    <asp:ListItem Value="2">Sell</asp:ListItem>

    <asp: DropDownList ID="EditDropDownCur1"
    DataSourceID="ObjectDataSource2" ... />
    <asp:ListItem ... />

    <asp:TextBox ID="txtEditAmount" ... />

    <asp:CheckBox ID="chkEditAct_Cur" runat=...
    onClick="QuoteConv(this);" Checked='<%
    #Eval("act_cur").ToString()=="1" ? false : true %>' />

    <input id="txtQuoteConv1" value="USA" readonly="readonly" ... />
    <input id="txtQuoteConv2" value="JPY" readonly="readonly" ... />

    I know I can do all this stuff through server-side code, but that would
    require AutoPostBack="True" on those controls I need to either validate
    or manipulate.

    Please help...


  2. #2
    Join Date
    Jan 2006
    Take a look at the source in the browser and you will be able to see the IDs that .net generates for your controls. I just use thoes IDs in my javascript if i need to do client side javascript on them. The IDs should be consistant unless you have some crazy dynamic stuff going on in your page.

Similar Threads

  1. Web services
    By madhavi pathi in forum .NET
    Replies: 4
    Last Post: 09-03-2002, 12:49 PM
  2. Replies: 0
    Last Post: 05-09-2002, 05:13 PM
  3. Replies: 0
    Last Post: 10-17-2001, 03:04 AM
  4. Replies: 0
    Last Post: 04-19-2001, 07:54 AM
  5. how to pass html from web server to client
    By devendra in forum Architecture and Design
    Replies: 0
    Last Post: 02-18-2001, 05:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center