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 10 3407
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
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
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
> 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
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
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).
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
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).
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
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).
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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....
|
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...
|
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...
|
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...
|
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...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
| |