DropDownList and Client Side OnChange - help!

J

James Radke

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
 
J

Jeffrey Tan[MSFT]

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" <[email protected]>
| From: "James Radke" <[email protected]>
| 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: <[email protected]>
| 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
|
|
|
 
J

James Radke

Jeffrey,

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

Jim

Jeffrey Tan said:
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
 
J

Jeffrey Tan[MSFT]

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" <[email protected]>
| From: "James Radke" <[email protected]>
| References: <[email protected]>
<[email protected]>
| 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: <[email protected]>
| 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
|
| | >
| > 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" <[email protected]>
| > | From: "James Radke" <[email protected]>
| > | 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: <[email protected]>
| > | 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
| > |
| > |
| > |
| >
|
|
|
 

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

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top