views:

217

answers:

1

With asp.NET control dropdownlist, there is a property AutoPostBack, if it is set "True", the whole page will be posted back.

If the aspx page include a html element "select" like:

<select id="list" name="list" runat="server"
    DataTextField="Name" DataValueField="ID" ></select>

and it data is filled by code-behind.

Question is: how to allow this Select have AutoPostBack function too?

A: 

Hey,

The DropDownList approach adds a __doPostBack('selectelementname', 'commandname'); call to the onchange event. When you change the value, this then proceeds to post back to the server, and then the ASP.NET control processes the postback data in LoadPostData method.

HTH.

Brian
okay, thanks. I did like this: <select id="dd" name="dd" runat="server" onchange="javascript:__doPostBack('dd', '')"></select>. then got error said "Object Expected..."
KentZhou
Huh, interesting... the HtmlSelect control does support loading posted data to the server... run the app and right-click in the browser, select view source, and find the HTML element definition. Make sure the ID and name properties are actually dd; if it is doing something with the name as in ct100$body$dd something like that, you have to use that value instead.
Brian