DropDownList and Client Side OnChange - help!

Discussion in 'ASP .Net Web Controls' started by James Radke, Oct 6, 2003.

  1. James Radke

    James Radke Guest

    Hello,

    I am using Visual Studio.NET 2003 to develop an application.

    On one of the forms, I have a asp:drop down list on a web page, and I want
    to clear an asp:label field every time the selection in the drop down list
    changes. And, I don't really want to waste the round trip to the server for
    such a simple task. So, I found some articles on the web that said to use
    the onchange="javascript: somefunction()" where somefunction is the
    javascript that you write and add to the page within the <script></script>
    blocks.

    I have tried this, and have gotten javascripts to work on other pages.. but
    never from the onchange of a dropdownlist. It appears that the function is
    never being executed?

    Can someone help me out with some sample code that works as to how I can
    succesfully use client-side scripting to accomplish this?

    Thanks!

    Jim
     
    James Radke, Oct 6, 2003
    #1
    1. Advertising

  2. Hi James,

    The server control will become the html control in the client explore side,
    so you can use client script to manipulate the HTML control that generate
    from server side control. You should just deal with the DOM object.

    For your DropDownList server control, it will generate the <Select><Option>
    HTML control, also, the Label control will become <Span> tag.

    So you can just add client script in the server side(this script will be
    put to the client side hold the line).

    Something like this:
    //add client script to the server control
    <asp:dropdownlist id="DropDownList1" runat="server"
    OnChange="javascript:dropdownchange()">

    //add client script to manipulate the html control that generated by the
    server control.
    //Label1 and DropDownList1 are the names of the client side HTML control.
    <script language="javascript">
    function dropdownchange()
    {
    document.all("Label1").innerText=document.all("DropDownList1").value;
    }
    </script>

    Does this resolve your problem?
    If you still have any question, please feel free to let me know.

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.

    --------------------
    | Reply-To: "James Radke" <>
    | From: "James Radke" <>
    | Subject: DropDownList and Client Side OnChange - help!
    | Date: Mon, 6 Oct 2003 17:48:16 -0500
    | Lines: 24
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    | Message-ID: <>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    | NNTP-Posting-Host: cpe-24-167-241-101.wi.rr.com 24.167.241.101
    | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
    | Xref: cpmsftngxa06.phx.gbl
    microsoft.public.dotnet.framework.aspnet.webcontrols:15168
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    |
    | Hello,
    |
    | I am using Visual Studio.NET 2003 to develop an application.
    |
    | On one of the forms, I have a asp:drop down list on a web page, and I want
    | to clear an asp:label field every time the selection in the drop down list
    | changes. And, I don't really want to waste the round trip to the server
    for
    | such a simple task. So, I found some articles on the web that said to use
    | the onchange="javascript: somefunction()" where somefunction is the
    | javascript that you write and add to the page within the <script></script>
    | blocks.
    |
    | I have tried this, and have gotten javascripts to work on other pages..
    but
    | never from the onchange of a dropdownlist. It appears that the function
    is
    | never being executed?
    |
    | Can someone help me out with some sample code that works as to how I can
    | succesfully use client-side scripting to accomplish this?
    |
    | Thanks!
    |
    | Jim
    |
    |
    |
     
    Jeffrey Tan[MSFT], Oct 7, 2003
    #2
    1. Advertising

  3. James Radke

    James Radke Guest

    Jeffrey,

    Thanks... it is working now! Much nicer to save that extra postback to do
    something simple like that.....

    Jim

    "Jeffrey Tan[MSFT]" <> wrote in message
    news:...
    >
    > Hi James,
    >
    > The server control will become the html control in the client explore

    side,
    > so you can use client script to manipulate the HTML control that generate
    > from server side control. You should just deal with the DOM object.
    >
    > For your DropDownList server control, it will generate the

    <Select><Option>
    > HTML control, also, the Label control will become <Span> tag.
    >
    > So you can just add client script in the server side(this script will be
    > put to the client side hold the line).
    >
    > Something like this:
    > //add client script to the server control
    > <asp:dropdownlist id="DropDownList1" runat="server"
    > OnChange="javascript:dropdownchange()">
    >
    > //add client script to manipulate the html control that generated by the
    > server control.
    > //Label1 and DropDownList1 are the names of the client side HTML control.
    > <script language="javascript">
    > function dropdownchange()
    > {
    > document.all("Label1").innerText=document.all("DropDownList1").value;
    > }
    > </script>
    >
    > Does this resolve your problem?
    > If you still have any question, please feel free to let me know.
    >
    > Best regards,
    > Jeffrey Tan
    > Microsoft Online Partner Support
    > Get Secure! - www.microsoft.com/security
    > This posting is provided "as is" with no warranties and confers no rights.
    >
    > --------------------
    > | Reply-To: "James Radke" <>
    > | From: "James Radke" <>
    > | Subject: DropDownList and Client Side OnChange - help!
    > | Date: Mon, 6 Oct 2003 17:48:16 -0500
    > | Lines: 24
    > | X-Priority: 3
    > | X-MSMail-Priority: Normal
    > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > | Message-ID: <>
    > | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    > | NNTP-Posting-Host: cpe-24-167-241-101.wi.rr.com 24.167.241.101
    > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
    > | Xref: cpmsftngxa06.phx.gbl
    > microsoft.public.dotnet.framework.aspnet.webcontrols:15168
    > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    > |
    > | Hello,
    > |
    > | I am using Visual Studio.NET 2003 to develop an application.
    > |
    > | On one of the forms, I have a asp:drop down list on a web page, and I

    want
    > | to clear an asp:label field every time the selection in the drop down

    list
    > | changes. And, I don't really want to waste the round trip to the server
    > for
    > | such a simple task. So, I found some articles on the web that said to

    use
    > | the onchange="javascript: somefunction()" where somefunction is the
    > | javascript that you write and add to the page within the

    <script></script>
    > | blocks.
    > |
    > | I have tried this, and have gotten javascripts to work on other pages..
    > but
    > | never from the onchange of a dropdownlist. It appears that the function
    > is
    > | never being executed?
    > |
    > | Can someone help me out with some sample code that works as to how I can
    > | succesfully use client-side scripting to accomplish this?
    > |
    > | Thanks!
    > |
    > | Jim
    > |
    > |
    > |
    >
     
    James Radke, Oct 7, 2003
    #3
  4. Hellow James,

    Oh, I am glad it works now.
    If you have any questions, please fee free to let me know, I am glad to
    work with you.

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.

    --------------------
    | Reply-To: "James Radke" <>
    | From: "James Radke" <>
    | References: <>
    <>
    | Subject: Re: DropDownList and Client Side OnChange - help!
    | Date: Tue, 7 Oct 2003 10:55:50 -0500
    | Lines: 101
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    | Message-ID: <>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    | NNTP-Posting-Host: cpe-24-167-241-101.wi.rr.com 24.167.241.101
    | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
    | Xref: cpmsftngxa06.phx.gbl
    microsoft.public.dotnet.framework.aspnet.webcontrols:15189
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    |
    | Jeffrey,
    |
    | Thanks... it is working now! Much nicer to save that extra postback to do
    | something simple like that.....
    |
    | Jim
    |
    | "Jeffrey Tan[MSFT]" <> wrote in message
    | news:...
    | >
    | > Hi James,
    | >
    | > The server control will become the html control in the client explore
    | side,
    | > so you can use client script to manipulate the HTML control that
    generate
    | > from server side control. You should just deal with the DOM object.
    | >
    | > For your DropDownList server control, it will generate the
    | <Select><Option>
    | > HTML control, also, the Label control will become <Span> tag.
    | >
    | > So you can just add client script in the server side(this script will be
    | > put to the client side hold the line).
    | >
    | > Something like this:
    | > //add client script to the server control
    | > <asp:dropdownlist id="DropDownList1" runat="server"
    | > OnChange="javascript:dropdownchange()">
    | >
    | > //add client script to manipulate the html control that generated by the
    | > server control.
    | > //Label1 and DropDownList1 are the names of the client side HTML
    control.
    | > <script language="javascript">
    | > function dropdownchange()
    | > {
    | > document.all("Label1").innerText=document.all("DropDownList1").value;
    | > }
    | > </script>
    | >
    | > Does this resolve your problem?
    | > If you still have any question, please feel free to let me know.
    | >
    | > Best regards,
    | > Jeffrey Tan
    | > Microsoft Online Partner Support
    | > Get Secure! - www.microsoft.com/security
    | > This posting is provided "as is" with no warranties and confers no
    rights.
    | >
    | > --------------------
    | > | Reply-To: "James Radke" <>
    | > | From: "James Radke" <>
    | > | Subject: DropDownList and Client Side OnChange - help!
    | > | Date: Mon, 6 Oct 2003 17:48:16 -0500
    | > | Lines: 24
    | > | X-Priority: 3
    | > | X-MSMail-Priority: Normal
    | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    | > | Message-ID: <>
    | > | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    | > | NNTP-Posting-Host: cpe-24-167-241-101.wi.rr.com 24.167.241.101
    | > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
    | > | Xref: cpmsftngxa06.phx.gbl
    | > microsoft.public.dotnet.framework.aspnet.webcontrols:15168
    | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    | > |
    | > | Hello,
    | > |
    | > | I am using Visual Studio.NET 2003 to develop an application.
    | > |
    | > | On one of the forms, I have a asp:drop down list on a web page, and I
    | want
    | > | to clear an asp:label field every time the selection in the drop down
    | list
    | > | changes. And, I don't really want to waste the round trip to the
    server
    | > for
    | > | such a simple task. So, I found some articles on the web that said to
    | use
    | > | the onchange="javascript: somefunction()" where somefunction is the
    | > | javascript that you write and add to the page within the
    | <script></script>
    | > | blocks.
    | > |
    | > | I have tried this, and have gotten javascripts to work on other
    pages..
    | > but
    | > | never from the onchange of a dropdownlist. It appears that the
    function
    | > is
    | > | never being executed?
    | > |
    | > | Can someone help me out with some sample code that works as to how I
    can
    | > | succesfully use client-side scripting to accomplish this?
    | > |
    | > | Thanks!
    | > |
    | > | Jim
    | > |
    | > |
    | > |
    | >
    |
    |
    |
     
    Jeffrey Tan[MSFT], Oct 8, 2003
    #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. =?Utf-8?B?TW9ua2V5Qm95?=
    Replies:
    2
    Views:
    453
    =?Utf-8?B?TW9ua2V5Qm95?=
    Jun 6, 2004
  2. Norm via DotNetMonster.com

    using the client side "onchange" event function

    Norm via DotNetMonster.com, Jun 15, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    4,884
    Norm via DotNetMonster.com
    Jun 15, 2005
  3. Boss302
    Replies:
    0
    Views:
    1,086
    Boss302
    Nov 21, 2006
  4. Bogdan
    Replies:
    2
    Views:
    679
    Bogdan
    Jun 9, 2008
  5. Zoe Hart
    Replies:
    1
    Views:
    389
    Scott Wisniewski
    Jan 8, 2004
Loading...

Share This Page