如何使带有OnChange事件的HtmlSelect控件触发函数后面的C#代码 [英] How to make HtmlSelect Control with OnChange event to trigger C# code behind function
问题描述
如何使用OnChange事件使"HTML选择控件"触发函数后面的C#代码
就像DropDownList控件的
How should I make "Html Select Control" with OnChange event to trigger C# code behind function
like ASP.NET SelectedIndexChanged of the DropDownList Control
例如
前端
<select runat="server" id="xx" onserverchange="xx_ServerChange">
<option>A</option>
<option>B</option>
<option>C</option>
</select>
后端
protected void xx_ServerChange(object sender, EventArgs e)
{
}
PS:
1.不是这样的选择服务器已更改事件,因为它必须创建另一个事件按钮.
2.不要使用asp:DropDownList
3.请不要使用任何重定向方法,例如Ajax或JQuery等...
PS:
1.Not like this Select server changed
event
,because it has to make another event button.
2.Don't use asp:DropDownList
3.Please don't use any redirect methods like Ajax or JQuery etc...
推荐答案
我找到了一种解决问题的好方法,将我的想法显示为以下代码
I've found a great way to handle my problems, showing my ideas as following code
前端
<select id="StartDate" onserverchange="StartDate_ServerChange" runat="server">
</select>
后端
protected void Page_Load(object sender, EventArgs e)
{
ClientScriptManager cs = Page.ClientScript;
this.StartDate.Attributes.Add("onchange", cs.GetPostBackEventReference(this.StartDate, this.StartDate.ID));
}
protected void StartDate_ServerChange(object sender, EventArgs e)
{
}
PS:两个参考文献
https://msdn.microsoft.com/en-us/library/ms153112(v = vs.110).aspx
https://blog.csdn.net/lovegonghui/article/details/51942241
这篇关于如何使带有OnChange事件的HtmlSelect控件触发函数后面的C#代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!