用asp.NET控件的下拉列表,有一个属性AutoPostBack,如果设置为“True”,则将整个页面回发。
如果 aspx 页面包含一个 html 元素“选择”,例如:
<select id="list" name="list" runat="server"
DataTextField="Name" DataValueField="ID" ></select>
它的数据由代码隐藏填充。
问题是:如何让这个 Select 也有 AutoPostBack 功能?
用asp.NET控件的下拉列表,有一个属性AutoPostBack,如果设置为“True”,则将整个页面回发。
如果 aspx 页面包含一个 html 元素“选择”,例如:
<select id="list" name="list" runat="server"
DataTextField="Name" DataValueField="ID" ></select>
它的数据由代码隐藏填充。
问题是:如何让这个 Select 也有 AutoPostBack 功能?
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.
您不能为 html 选择控件应用自动回发属性。要调用编写在 c# 代码页(服务器端)中的函数,您需要使用 web 服务。您可以在 html 选择控件的“onchange”事件上调用 javascript 函数(客户端)。