HTML Select控件的服务器事件 [英] Server Event for HTML Select control
问题描述
如何为HTML Select控件添加服务器事件?
How can I add a server event for an HTML Select control?
HTML代码是这样的:
HTML code is like this:
<div class="ui-widget">
<select id="Select1" runat="server">
<option>Select one...</option>
<option>ActionScript</option>
<option>AppleScript</option>
<option>Asp</option>
<option>BASIC</option>
</select>
</div>
C#代码如下:
public void Select1_SomethingChange(object sender, EventArgs e)
{
//random code
}
现在,我知道它是行不通的,HTML的第二行需要某种类型的属性..我已经尝试了我能找到的唯一两个,下面是这两个
Now I know just as is it won't work, the 2nd line of the HTML needs an attribute of some kind.. I already tried the only 2 I could find which are these two below
<select id="Select1" runat="server" onServerChanged="Select1_SomethingChange">
<select id="Select1" runat="server" onSelectedIndexChanged="Select1_SomethingChange">
问题在于,第一个选项事件永远不会触发,而第二个选项根本不存在.请在这里帮助我,欢迎您提供帮助.
The problem is that the first options event never fires, and the 2nd option just doesn't exist. Please help me out here, any help is welcome.
推荐答案
将 runat ="server"
添加到原本正常的HTML元素中时,它将成为 HtmlControl
在服务器端代码中.哪个不会暴露很多事件一个>.为了获得更丰富的服务器端事件,您需要使用ASP.NET控件.在这种情况下,这将是 DropDownList
,它拥有您要查找的事件.
When you add runat="server"
to an otherwise normal HTML element, it becomes an HtmlControl
in the server-side code. Which doesn't expose a lot of events. In order to get richer server-side eventing, you need to use the ASP.NET controls. In this case that would be a DropDownList
, which has the events you're looking for.
类似这样的东西:
<div class="ui-widget">
<asp:DropDownList id="Select1" OnSelectedIndexChanged="Select1_SomethingChange" runat="server">
<asp:ListItem Selected="True" Value="White"> White </asp:ListItem>
<asp:ListItem Value="Select one...">Select one...</asp:ListItem>
<asp:ListItem Value="ActionScript">ActionScript</asp:ListItem>
<asp:ListItem Value="AppleScript">AppleScript</asp:ListItem>
<asp:ListItem Value="Asp">Asp</asp:ListItem>
<asp:ListItem Value="BASIC">BASIC</asp:ListItem>
</asp:DropDownList>
</div>
这篇关于HTML Select控件的服务器事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!