[英]How do you call a C# function from an ASP.NET event?
I have written a function in my .cs page. 我已经在.cs页面中编写了一个函数。 On the event onselectedindexchanged in .aspx I want to call this function. 在.aspx中onselectedindex更改的事件上,我想调用此函数。
How do I do this? 我该怎么做呢?
If you had the following method in your *.cs file: 如果您的* .cs文件中具有以下方法:
public void DoSomething()
{
}
You could wrap the call in an event handler: 您可以将调用包装在事件处理程序中:
void RadioButtonList1_IndexChangedHandler(object sender, EventArgs e)
{
DoSomething();
}
And your *.aspx code would look like: 您的* .aspx代码如下所示:
<asp:RadioButtonList id="RadioButtonList1"
OnSelectedIndexChanged="RadioButtonList1_IndexChangedHandler"
AutoPostBack="true"
runat="server"/>
Just point this function to onselectedindexchanged
property of the drop down list. 只需将此函数指向下拉列表的onselectedindexchanged
属性即可。
onselectedindexchanged="DropDownList1_SelectedIndexChanged"
Can you also explain how you added the Drodown List to the page? 您还能解释一下如何将“下拉列表”添加到页面吗?
使用<%=%>标签
<%= Function() %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.