Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 13th, 2006, 02:54 AM
Friend of Wrox
 
Join Date: Jun 2004
Location: Alhambra, ca, USA.
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to cast ASP Drop Down List to HtmlSelect?

Hello
I have an <asp:Drop Down List/> that is dynamically populated by Javascript depending on what the previous Drop Down List selection is. However, on "Search" button click, I want the server to take the Selected Value from <asp:Drop Down List/> and pass it to a parameter.
The problem is, when I step through the code in Javascript, the DDL has the property of Form1.ddl.option.value and Form1.ddl.option.text. When I step through the same ddl in Code behind, there is no value for DataTextField and DataValueField.

I was trying to cast the ASP DDL to HtmlSelect, because the Javascript populates the ddl as HtmlSelect. This is an invalid cast and VS.NET 2003 won't let me.

So what can I do???
Help

  #2 (permalink)  
Old February 13th, 2006, 12:56 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You can't cast it. You could also use <select runat="server">, which would be the HtmlSelect control instead. When rendered, the asp:DropDownList is a <select> element, so I dont' now what the problem is...

Brian
  #3 (permalink)  
Old February 13th, 2006, 12:57 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Oh, and DataTextField and DataValueField are for databinding; the selectedvalue is for the selected value or selecteditem.text for the text, in the code-behind.

Brian
  #4 (permalink)  
Old February 13th, 2006, 11:04 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

There will be an inherent problem if you change the <select> elements contents for a server control. The server control will restore the contents of the option list from viewstate and then apply whatever change was posted. So if you start with the options 1, 2 & 3, then change those options in javascript to 4, 5 & 6, the server side code will ignore the client side change in the list and restore the control with 1, 2 & 3. It will also attempt to apply the change (now you'll have either 4, 5 or 6 selected) but it can't find them in the current list so it will default back to the first option (1). This can cause erroneous index change events or other strange things to happen. If you want to be able to support this client-side option list change behavior, you'll have to use standard non-server form elements and manually capture the post values using the Request.Form collection. This is doing it old school style but it could be done.

-Peter
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
drop down list ashu_gupta75 Excel VBA 1 October 15th, 2007 05:52 PM
drop down list values based on another drop down noor ASP.NET 1.0 and 1.1 Basics 3 July 5th, 2005 09:57 AM
Drop Down List mrideout BOOK: Beginning ASP.NET 1.0 6 March 18th, 2005 03:32 AM



All times are GMT -4. The time now is 02:05 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.