473,396 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Getting Options collection from Select Box in ASP.

I've been wracking my brains trying to figure out how to do this, so I thought I would pop it out here for the experts, since my earlier attempts have ended in failure.

I'm trying to retrive a collection of <OPTION>'s from an HTML select list, and then loop through them to make them options in a CheckBoxList in VB.

Does anyone have a quick and dirty way to use Javascript to get this information, and then loop through it in VB to populate the drop down?

I'm not very strong in using Javascript inside my VB, so I think that's where the source of my issues come from.

Thanks!
Jun 12 '07 #1
9 2358
Frinavale
9,735 Expert Mod 8TB
I've been wracking my brains trying to figure out how to do this, so I thought I would pop it out here for the experts, since my earlier attempts have ended in failure.

I'm trying to retrive a collection of <OPTION>'s from an HTML select list, and then loop through them to make them options in a CheckBoxList in VB.

Does anyone have a quick and dirty way to use Javascript to get this information, and then loop through it in VB to populate the drop down?

I'm not very strong in using Javascript inside my VB, so I think that's where the source of my issues come from.

Thanks!
Why can't remove the <select> list and replace it with a dropDownList?

-Frinny
Jun 12 '07 #2
Why can't remove the <select> list and replace it with a dropDownList?

-Frinny
I want to have a checkboxlist that will retain the values and give the users a better multiple selection list than the standard drop down list.

Since I'm embedding this in another app that autogenerates the select list, I have to have that and that's where I plan on getting the initial values.
Jun 12 '07 #3
Frinavale
9,735 Expert Mod 8TB
I want to have a checkboxlist that will retain the values and give the users a better multiple selection list than the standard drop down list.

Since I'm embedding this in another app that autogenerates the select list, I have to have that and that's where I plan on getting the initial values.
Sounds like an interesting project.

The only thing I can think of right now is make a hidden field and store the values from the <select> list into it. Then grab the hidden field in your data in your .NET code and parse it to generate your checkBoxList:

Eg...create a hidden field in your form
->you can do this in your .Net code using ClientScript.RegisterHiddenField("idOfHiddenField" ,"intialValue")

Then use your JavaScript to populate this hidden field (just add all the values of each option in your select list separated by some delimiter)

Then in your server side code grab the hidden field value:

Dim value As String = postCollection(IdOfHiddenField)

Then use the String.Split('delimiter') on your hidden field ...
Since it's your JavaScript that will generate the value for the hidden field you know what its value is delimited by.

Hope you see where I'm going with this....hope this helps!

-Frinny
Jun 12 '07 #4
What is the PostCollection? It doesn't seem to be a method I can access directly, is it a member of something else I have to reference?

I won't use a hidden field because I plan on hiding the select box after I get the values out of it.
Jun 12 '07 #5
Frinavale
9,735 Expert Mod 8TB
What is the PostCollection? It doesn't seem to be a method I can access directly, is it a member of something else I have to reference?

I won't use a hidden field because I plan on hiding the select box after I get the values out of it.
Oh.....
This is more complicated than I thought.
PostCollection is a parameter passed in to a method that I was using for reference during my last post...

The method is
Expand|Select|Wrap|Line Numbers
  1. Private Function LoadPostData(ByVal postDataKey As String, ByVal postCollection As NameValueCollection) As Boolean Implements IPostBackDataHandler.LoadPostData
It was created to satisfy my implementation of the IPostBackDataHandler interface.

Give me a minute and let me see if there is a way to do this without having to implement this interface.

-Frinny
Jun 12 '07 #6
Frinavale
9,735 Expert Mod 8TB
Ok its easier than I thought...use your Request object's Params property to retrieve the parameters passed to your application.

Eg. C#:
Expand|Select|Wrap|Line Numbers
  1. String strValue = Request.Params["KeyName"];
  2.  
VB:
Expand|Select|Wrap|Line Numbers
  1.  Dim strValue As String = Request.Params("KeyName")
Just remember that hidden fields can be changed by a malicious user so be sure to validate the input you grab from your Request object.

Cheers!

-Frinny
Jun 12 '07 #7
Frinavale
9,735 Expert Mod 8TB
What is the PostCollection? It doesn't seem to be a method I can access directly, is it a member of something else I have to reference?

I won't use a hidden field because I plan on hiding the select box after I get the values out of it.
Oh,
How do you plan on hiding the select box after you get the values out of it?
I thought it was part of someone else's code?
Jun 12 '07 #8
Oh, I can run javascript against the fields that are currently on the form, and can run scripting against the IFRAME that is showing this ASP.Net control.

Is that one of those pieces of information that makes this all a lot easier?

If I could use javascript to grab the options collection and then populate the checkbox list with that, then that would work for me as well, but I didn't think that could be done...
Jun 12 '07 #9
Frinavale
9,735 Expert Mod 8TB
Oh, I can run javascript against the fields that are currently on the form, and can run scripting against the IFRAME that is showing this ASP.Net control.

Is that one of those pieces of information that makes this all a lot easier?

If I could use javascript to grab the options collection and then populate the checkbox list with that, then that would work for me as well, but I didn't think that could be done...
I don't know if it can be done without first storing it into a hidden field which your .Net code can access and populate the check box from there...
Jun 13 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Christopher Benson-Manica | last post by:
I understand that the options property of a select element is an array of the options displayed by the select element. If that's so, then why can't I sort the array? Rather, I *want* to sort the...
2
by: BrianP | last post by:
Hi, I have had to invent a work-around to get past what looks like a JavaScript bug, the malfunctioning Perl-like JavaScript array functions including SPLICE() and UNSHIFT(). I have boiled it...
6
by: rishabhshrivastava | last post by:
Hey All, Can someone suggest me a way to get the values of CheckBox(es) selected in a CheckBoxList control using JAVASCRIPT. I am pasting my current code gere but its not working need some...
3
by: TKapler | last post by:
i got this simmple function, It stays on onChange on select and on change it hides all objects with ID equal to select name plus the optionvalue. It works perfectly in Opera and FF, but IE crashes...
5
by: jdzemke | last post by:
I am getting 'options' is null or not an object using when using a dynamic dataset with a dropdown list in an html form. I am filling-in a text field and filtering the values in the drop-down. ...
4
by: jeet | last post by:
Plz help me.Problem is that On the first page I display all other user with checkbox and give user option to select only two user which he wants to send message. Tell me please how I'll get those...
5
by: Max | last post by:
Is there any way to set a select-multiple type <select multiple="multiple"with multiple selected options in scripting? Any idea about this is appreciative.
1
by: laredotornado | last post by:
Hi, I have a select menu on my page. What is the easiest way to get the VALUE attribute of each of the options starting from index 1 and put all those into their own array? If iterating over...
8
by: chanshaw | last post by:
Alright this runs just fine in IE but in firefox I get nothing function startup() { if (window.ActiveXObject) { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); }...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.