Groups | Blog | Home
all groups > asp.net > march 2005 >

asp.net : HtmlSelect and PostBack?


Peter Rilling
3/6/2005 8:06:19 PM
The problem with what you are doing is that ASP.NET generates the object
model for the page during the Page_Init event. In order for the server to
dispatch to the event handler for the control, the control must be fully
formed before the Load event happens. If you populate it on the client,
there is no way for the server to know what items are available and
therefore will not dispatch to the event.

In other words, you will have to do this some other way such as storing
information in a hidden field and then process it yourself during the
Page_Load.

[quoted text, click to view]

xenophon
3/6/2005 10:48:30 PM

I created an HtmlSelect in my ASP.NET page template (setting
runat="server" in its tag), double-clicked it in the Designer, and
Visual Studio automagically made the declaration and Event Wireup and
associated method.

However, I use JavaScript on the client to populate the list and a
LinkButton to PostBack. In the Page_Load, there are no items in the
HtmlSelect.

Does anyone have an example of how this should work?

Thanks.

Karl Seguin
3/6/2005 11:08:56 PM
Xeno:
Check out http://openmymind.net/FAQ.aspx?documentId=1

Client-side added controls won't show up on the server side because the
viewstate has already been rendered. You can still use Request.Form() to
get the selected values though.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


[quoted text, click to view]

Sylvain Lafontaine
3/6/2005 11:11:50 PM
When you are populating a Select control on the client side, absolutely
nothing of this is sent back by the browser to the server and only the
selected value is posted back. This is the normal behavior of the browser.

S. L.

[quoted text, click to view]

AddThis Social Bookmark Button