HtmlSelect and PostBack?

X

xenophon

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.
 
P

Peter Rilling

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.
 
S

Sylvain Lafontaine

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top