Rendering ASP.NET control out to HTML string won't render selected event
I'm rendering a DropDownList
in my Visual Studio 2005 ASP.NET code behind page out to an HtmlTextWriter
, but when I try to add the SelectedIndexChanged
even开发者_Go百科t that doesn't get rendered.
Any ideas? Is this even possible?
Update: I've tried setting AutoPostBack=true. Is it possible trying to render the control via the HTMLTextWriter isn't supported?
Adding an event handler to the SelectedIndexChanged
event (or any other server side event) will not affect the markup produced when rendering the DropDownList
control. The event handler is defined and executed only on the server, and needs nothing extra in the client side markup.
The SelectedIndexChanged
event will be triggered on postback, if the selected value in the list has changed between since the last rendering. The view state is used to track the previously selected value, and the posted form value from the <select>
holds the new value to be compared.
If you want your page to perform an automatic postback when the selected index of the DropDownList
changes (on the client side), set the AutoPostback = true
on the control. This will cause a minor change to the rendered markup, which will now include a client side (JavaScript) event registration on the <select>
, triggering a submit of the surrounding form when its selected index is changed.
精彩评论