473,386 Members | 1,710 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,386 software developers and data experts.

Listbox does not appear in Request.Form

DropDown lists and Listboxes do not appear in the list of controls and
values passed back to the server on PostBack in Request.Form object. Can
someone confirm this to be correct and possibly answer why ?

The impact of this is that values added via javascript will never make it
back to the server side code unless one does some jiggery pokery with hidden
fields etc. If this is true, then I would like to understand the reason
behind the design decision and if this has been addressed in VS2005 ?
Cheers - Mr N
Nov 19 '05 #1
10 3435
Hello, Mr. Newbie.

re:
The impact of this is that values added via javascript will never make it back to the
server side code unless one does some jiggery pokery with hidden fields
JavaScript runs client-side and forms run server-side.

You need to pass the values to the server from your javascript,
which is running where the server will never see it.

re: If this is true, then I would like to understand the reason behind the design decision
and if this has been addressed in VS2005 ? ..
The reason is "by design", per the explanation above.

What I wonder is why you are still sticking to Request.Form,
instead of using the .NET native Request.Params, which returns
a combined collection of QueryString, Form, ServerVariables, and Cookies.

Request.Params works the same way in ASP.NET 1.x, 2.0 and WinFx :

http://msdn.microsoft.com/library/de...aramstopic.asp

http://msdn2.microsoft.com/en-us/library/dt24b615

http://winfx.msdn.microsoft.com/libr...est_Params.asp


Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Mr Newbie" <he**@now.com> wrote in message news:OH*************@TK2MSFTNGP15.phx.gbl... DropDown lists and Listboxes do not appear in the list of controls and values passed
back to the server on PostBack in Request.Form object. Can someone confirm this to be
correct and possibly answer why ?

The impact of this is that values added via javascript will never make it back to the
server side code unless one does some jiggery pokery with hidden fields etc. If this is
true, then I would like to understand the reason behind the design decision and if this
has been addressed in VS2005 ?
Cheers - Mr N

Nov 19 '05 #2
This isn't an ASP.Net issue, it's how HTML and HTTP work. For list
controls, such as <input type="radio/checkbox" and <select> only the
SELECTED value is passed in the Request.Form. This is how the first form
worked in HTML 1.0 and how it works now.

ViewState tries to resolve this problem by taking all the values before the
page is rendered and serializing said values to a hidden field, which can
then be used to recreate the controls on postback. If you have a listbox
with 10 items, then those 10 items will be serialized to a hidden field. if
you dynamically add an 11th item using javascript to the control, the value
still won't be added to the hidden field and thus won't appear during
postback. This is neither a bug nor a limitation of ASP.Net.

You need to do some hidden field trick. It's often easier to copy the
selected value to a hidden field (assuming you need to know what the
selected value was) and then select all the values in the
Select/radio/checkbox It results in less code...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Mr Newbie" <he**@now.com> wrote in message
news:OH*************@TK2MSFTNGP15.phx.gbl...
DropDown lists and Listboxes do not appear in the list of controls and
values passed back to the server on PostBack in Request.Form object. Can
someone confirm this to be correct and possibly answer why ?

The impact of this is that values added via javascript will never make it
back to the server side code unless one does some jiggery pokery with
hidden fields etc. If this is true, then I would like to understand the
reason behind the design decision and if this has been addressed in VS2005
?
Cheers - Mr N

Nov 19 '05 #3
I dont think you have understood me, perhaps I did not make myself clear.

I am well aware that Javascript runs client side and web forms run server
side. The question is regarding ListBox and DropDown boxes. Why does ASP.NET
not preserve the 'STATE' of those controls ?

The point being is that controls such as TextBox's and Buttons etc have
their state preserved by using the Viewstate. For example if I add client
side a charavter to a textbox, ASP.NET will update the viewstate and whent
the form is posted back to the client. That change is reflected. However,
with ListBox and DropDown, this is not the case ( Apparently ) , the
question is why ?

This is not really anything to do with Javascript other than this is how I
would add items client side if I wanted to.

Does this make my question clearer ?


"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:OH**************@tk2msftngp13.phx.gbl...
Hello, Mr. Newbie.

re:
The impact of this is that values added via javascript will never make it
back to the server side code unless one does some jiggery pokery with
hidden fields


JavaScript runs client-side and forms run server-side.

You need to pass the values to the server from your javascript,
which is running where the server will never see it.

re:
If this is true, then I would like to understand the reason behind the
design decision and if this has been addressed in VS2005 ?

.
The reason is "by design", per the explanation above.

What I wonder is why you are still sticking to Request.Form,
instead of using the .NET native Request.Params, which returns
a combined collection of QueryString, Form, ServerVariables, and Cookies.

Request.Params works the same way in ASP.NET 1.x, 2.0 and WinFx :

http://msdn.microsoft.com/library/de...aramstopic.asp

http://msdn2.microsoft.com/en-us/library/dt24b615

http://winfx.msdn.microsoft.com/libr...est_Params.asp


Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Mr Newbie" <he**@now.com> wrote in message
news:OH*************@TK2MSFTNGP15.phx.gbl...
DropDown lists and Listboxes do not appear in the list of controls and
values passed back to the server on PostBack in Request.Form object. Can
someone confirm this to be correct and possibly answer why ?

The impact of this is that values added via javascript will never make it
back to the server side code unless one does some jiggery pokery with
hidden fields etc. If this is true, then I would like to understand the
reason behind the design decision and if this has been addressed in
VS2005 ?
Cheers - Mr N


Nov 19 '05 #4
> This isn't an ASP.Net issue, it's how HTML and HTTP work. For list
controls, such as <input type="radio/checkbox" and <select> only the
SELECTED value is passed in the Request.Form. This is how the first form
worked in HTML 1.0 and how it works now.
I tried selecting a value which was added using Javascript, but this did
not get passed back either. So are you saying then that only the selected
value or values are passed back if the values were generated by asp.net ?



"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:eY***************@TK2MSFTNGP15.phx.gbl...
ViewState tries to resolve this problem by taking all the values before
the page is rendered and serializing said values to a hidden field, which
can then be used to recreate the controls on postback. If you have a
listbox with 10 items, then those 10 items will be serialized to a hidden
field. if you dynamically add an 11th item using javascript to the
control, the value still won't be added to the hidden field and thus won't
appear during postback. This is neither a bug nor a limitation of
ASP.Net.

You need to do some hidden field trick. It's often easier to copy the
selected value to a hidden field (assuming you need to know what the
selected value was) and then select all the values in the
Select/radio/checkbox It results in less code...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Mr Newbie" <he**@now.com> wrote in message
news:OH*************@TK2MSFTNGP15.phx.gbl...
DropDown lists and Listboxes do not appear in the list of controls and
values passed back to the server on PostBack in Request.Form object. Can
someone confirm this to be correct and possibly answer why ?

The impact of this is that values added via javascript will never make it
back to the server side code unless one does some jiggery pokery with
hidden fields etc. If this is true, then I would like to understand the
reason behind the design decision and if this has been addressed in
VS2005 ?
Cheers - Mr N


Nov 19 '05 #5
Just to clarify in addition to my post...TextBoxes don't work like you think
they do with ViewState. The value of a textbox isn't preserved via
ViewState. Since there's only 1 value and HTML specifications say that the
value has to be passed via REquest.Form, it would be foolish for ASP.Net to
also maintain it in ViewState (waste of space).

ViewState is used where/when Request.Form can't. Namely for controls that
don't participate in the form submission (datagrid for example) as well as
controls who only partially participate in form submission (only the
selected radio input gets passed).

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Mr Newbie" <he**@now.com> wrote in message
news:ur*************@TK2MSFTNGP12.phx.gbl...
I dont think you have understood me, perhaps I did not make myself clear.

I am well aware that Javascript runs client side and web forms run server
side. The question is regarding ListBox and DropDown boxes. Why does
ASP.NET not preserve the 'STATE' of those controls ?

The point being is that controls such as TextBox's and Buttons etc have
their state preserved by using the Viewstate. For example if I add client
side a charavter to a textbox, ASP.NET will update the viewstate and whent
the form is posted back to the client. That change is reflected. However,
with ListBox and DropDown, this is not the case ( Apparently ) , the
question is why ?

This is not really anything to do with Javascript other than this is how I
would add items client side if I wanted to.

Does this make my question clearer ?


"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:OH**************@tk2msftngp13.phx.gbl...
Hello, Mr. Newbie.

re:
The impact of this is that values added via javascript will never make
it back to the server side code unless one does some jiggery pokery with
hidden fields


JavaScript runs client-side and forms run server-side.

You need to pass the values to the server from your javascript,
which is running where the server will never see it.

re:
If this is true, then I would like to understand the reason behind the
design decision and if this has been addressed in VS2005 ?

.
The reason is "by design", per the explanation above.

What I wonder is why you are still sticking to Request.Form,
instead of using the .NET native Request.Params, which returns
a combined collection of QueryString, Form, ServerVariables, and Cookies.

Request.Params works the same way in ASP.NET 1.x, 2.0 and WinFx :

http://msdn.microsoft.com/library/de...aramstopic.asp

http://msdn2.microsoft.com/en-us/library/dt24b615

http://winfx.msdn.microsoft.com/libr...est_Params.asp


Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Mr Newbie" <he**@now.com> wrote in message
news:OH*************@TK2MSFTNGP15.phx.gbl...
DropDown lists and Listboxes do not appear in the list of controls and
values passed back to the server on PostBack in Request.Form object. Can
someone confirm this to be correct and possibly answer why ?

The impact of this is that values added via javascript will never make
it back to the server side code unless one does some jiggery pokery with
hidden fields etc. If this is true, then I would like to understand the
reason behind the design decision and if this has been addressed in
VS2005 ?
Cheers - Mr N



Nov 19 '05 #6
OK, that makes sense I suppose. Presumably though viewstate is used with
textboxes to determine and fire the text changed event by comparing the text
before and that which is preserved in viewstate, or do I have that wrong as
well.

I dont seem to be doing very well today!

Cheers Mr N

Just to clarify in addition to my post...TextBoxes don't work like you
think they do with ViewState. The value of a textbox isn't preserved via
ViewState. Since there's only 1 value and HTML specifications say that
the value has to be passed via REquest.Form, it would be foolish for
ASP.Net to also maintain it in ViewState (waste of space).

ViewState is used where/when Request.Form can't. Namely for controls that
don't participate in the form submission (datagrid for example) as well as
controls who only partially participate in form submission (only the
selected radio input gets passed).


Nov 19 '05 #7
See Karl's answer for specific recommendations.

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Mr Newbie" <he**@now.com> wrote in message news:ur*************@TK2MSFTNGP12.phx.gbl...
I dont think you have understood me, perhaps I did not make myself clear.

I am well aware that Javascript runs client side and web forms run server side. The
question is regarding ListBox and DropDown boxes. Why does ASP.NET not preserve the
'STATE' of those controls ?

The point being is that controls such as TextBox's and Buttons etc have their state
preserved by using the Viewstate. For example if I add client side a charavter to a
textbox, ASP.NET will update the viewstate and whent the form is posted back to the
client. That change is reflected. However, with ListBox and DropDown, this is not the
case ( Apparently ) , the question is why ?

This is not really anything to do with Javascript other than this is how I would add
items client side if I wanted to.

Does this make my question clearer ?


"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:OH**************@tk2msftngp13.phx.gbl...
Hello, Mr. Newbie.

re:
The impact of this is that values added via javascript will never make it back to the
server side code unless one does some jiggery pokery with hidden fields


JavaScript runs client-side and forms run server-side.

You need to pass the values to the server from your javascript,
which is running where the server will never see it.

re:
If this is true, then I would like to understand the reason behind the design decision
and if this has been addressed in VS2005 ?

.
The reason is "by design", per the explanation above.

What I wonder is why you are still sticking to Request.Form,
instead of using the .NET native Request.Params, which returns
a combined collection of QueryString, Form, ServerVariables, and Cookies.

Request.Params works the same way in ASP.NET 1.x, 2.0 and WinFx :

http://msdn.microsoft.com/library/de...aramstopic.asp

http://msdn2.microsoft.com/en-us/library/dt24b615

http://winfx.msdn.microsoft.com/libr...est_Params.asp


Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Mr Newbie" <he**@now.com> wrote in message
news:OH*************@TK2MSFTNGP15.phx.gbl...
DropDown lists and Listboxes do not appear in the list of controls and values passed
back to the server on PostBack in Request.Form object. Can someone confirm this to be
correct and possibly answer why ?

The impact of this is that values added via javascript will never make it back to the
server side code unless one does some jiggery pokery with hidden fields etc. If this
is true, then I would like to understand the reason behind the design decision and if
this has been addressed in VS2005 ?
Cheers - Mr N



Nov 19 '05 #8
No, I think you are right about that part :) i could look into it, but
let's say you are...can't think of how else it would do it ...nice catch!

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Mr Newbie" <he**@now.com> wrote in message
news:eq**************@TK2MSFTNGP14.phx.gbl...
OK, that makes sense I suppose. Presumably though viewstate is used with
textboxes to determine and fire the text changed event by comparing the
text before and that which is preserved in viewstate, or do I have that
wrong as well.

I dont seem to be doing very well today!

Cheers Mr N

Just to clarify in addition to my post...TextBoxes don't work like you
think they do with ViewState. The value of a textbox isn't preserved via
ViewState. Since there's only 1 value and HTML specifications say that
the value has to be passed via REquest.Form, it would be foolish for
ASP.Net to also maintain it in ViewState (waste of space).

ViewState is used where/when Request.Form can't. Namely for controls
that don't participate in the form submission (datagrid for example) as
well as controls who only partially participate in form submission (only
the selected radio input gets passed).


Nov 19 '05 #9
No, you should be seeing the value in Request.Form

Request.Form is totally independant of ViewState or server-side this or
client-side that...it's much more basic than all of that. Whatever value is
selected, however it got there, should show up. The only thing I can think
of, without seeing code, is that ASP.Net does generate unique clientId's so
if you have

<asp:dropdownlist id="SomeId" runat="server" />

it might get rendered as

<select name="clt0:SomeId" > ... </select>

Form submission works on Name not Id, so I only showed the Name.

Anyways, you might be doing Request.Form["SomeId"] when really you should
be doing Request.Form[someId.ClientId] but that'll only happen when your
controls are nested.

Two things you can do. Turn tracing on in the page <%@ Page trace="True"
.... %> and look at the output, or debug, add a breakpoint in Page_Load and
Add a Watch to REquest.Form

karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Mr Newbie" <he**@now.com> wrote in message
news:ec**************@TK2MSFTNGP14.phx.gbl...
This isn't an ASP.Net issue, it's how HTML and HTTP work. For list
controls, such as <input type="radio/checkbox" and <select> only the
SELECTED value is passed in the Request.Form. This is how the first form
worked in HTML 1.0 and how it works now.


I tried selecting a value which was added using Javascript, but this did
not get passed back either. So are you saying then that only the selected
value or values are passed back if the values were generated by asp.net ?



"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:eY***************@TK2MSFTNGP15.phx.gbl...

ViewState tries to resolve this problem by taking all the values before
the page is rendered and serializing said values to a hidden field, which
can then be used to recreate the controls on postback. If you have a
listbox with 10 items, then those 10 items will be serialized to a hidden
field. if you dynamically add an 11th item using javascript to the
control, the value still won't be added to the hidden field and thus
won't appear during postback. This is neither a bug nor a limitation of
ASP.Net.

You need to do some hidden field trick. It's often easier to copy the
selected value to a hidden field (assuming you need to know what the
selected value was) and then select all the values in the
Select/radio/checkbox It results in less code...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Mr Newbie" <he**@now.com> wrote in message
news:OH*************@TK2MSFTNGP15.phx.gbl...
DropDown lists and Listboxes do not appear in the list of controls and
values passed back to the server on PostBack in Request.Form object. Can
someone confirm this to be correct and possibly answer why ?

The impact of this is that values added via javascript will never make
it back to the server side code unless one does some jiggery pokery with
hidden fields etc. If this is true, then I would like to understand the
reason behind the design decision and if this has been addressed in
VS2005 ?
Cheers - Mr N



Nov 19 '05 #10
I found another way around this. If you hijack the form submit, you can
select all members of the ListBox and then submit the code, this is only any
good if you dont want to select a single item from the list. Otherwise your
hidden field idea is the only way forward.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

If IsPostBack Then

Dim col As System.Collections.Specialized.NameValueCollection

Dim listItemsArray() As String

Dim strListItems As String

col = Request.Form

strListItems = col.Item("ListBox1")

listItemsArray = strListItems.Split(",")

ListBox1.Items.Clear()

For Each s As String In listItemsArray

ListBox1.Items.Add(s)

Next



End If


"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl...
No, I think you are right about that part :) i could look into it, but
let's say you are...can't think of how else it would do it ...nice catch!

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Mr Newbie" <he**@now.com> wrote in message
news:eq**************@TK2MSFTNGP14.phx.gbl...
OK, that makes sense I suppose. Presumably though viewstate is used with
textboxes to determine and fire the text changed event by comparing the
text before and that which is preserved in viewstate, or do I have that
wrong as well.

I dont seem to be doing very well today!

Cheers Mr N

Just to clarify in addition to my post...TextBoxes don't work like you
think they do with ViewState. The value of a textbox isn't preserved
via ViewState. Since there's only 1 value and HTML specifications say
that the value has to be passed via REquest.Form, it would be foolish
for ASP.Net to also maintain it in ViewState (waste of space).

ViewState is used where/when Request.Form can't. Namely for controls
that don't participate in the form submission (datagrid for example) as
well as controls who only partially participate in form submission (only
the selected radio input gets passed).



Nov 19 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Crystal | last post by:
Ok, I know this sounds weird, but it's really bugging me. I have a few list boxes on my form (basic pick a month, year, state stuff) and you can only choose one value. I need to be able to run a...
4
by: f_salazar | last post by:
English Version !! Hi !! I have a page with a Form, inside the form I have listbox with 'X' elements. Wend I submit the page, an ASP process inside the page have to read those elements and...
1
by: Annette Massie | last post by:
I would like to have a form that lists current addresses being used. On this form I would also like to have a command button that would allow the user to add an address if they do not see it...
9
by: Megan | last post by:
Hi- I'm creating a database of music bands with their cds and songs. I'm trying to program an SQL statement so that I can enter a string of text in a textbox, press the 'Enter' key, and have...
0
by: Ray | last post by:
Folks, I have just created a simple procedure that does the following: Determines the width of the columns of a listbox. Places a button of the correct size above each column as the form opens....
13
by: Gittyup | last post by:
Help please, We have a form, based on a query, that contains a listbox. The contents of the listbox are based on the results of the query. When the form is opened, the user selects an item...
1
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What...
6
by: Janaka | last post by:
Help! I have two ListBox controls on my web form. The first one gets populated on entry with values from the DB. I then use JavaScript to copy options from this ListBox to my second one. (I...
5
by: MelindaM | last post by:
Hi guys, I created a form for searching through a parts library that I have stored in a MySQL database. I'm not new to web programming but this is my first time using PHP and Ajax. I have four...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.