开发者

How do you call a C# function from an ASP.NET event?

开发者 https://www.devze.com 2023-01-12 10:42 出处:网络
I have written a function in my .cs page.On the event onselectedindexchanged in .aspx I want to call this func开发者_JAVA技巧tion.

I have written a function in my .cs page. On the event onselectedindexchanged in .aspx I want to call this func开发者_JAVA技巧tion.

How do I do this?


If you had the following method in your *.cs file:

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:

<asp:RadioButtonList id="RadioButtonList1" 
        OnSelectedIndexChanged="RadioButtonList1_IndexChangedHandler"
        AutoPostBack="true"
        runat="server"/>


Just point this function to onselectedindexchanged property of the drop down list.

onselectedindexchanged="DropDownList1_SelectedIndexChanged"

Can you also explain how you added the Drodown List to the page?


With the <%= %> tags

<%= Function() %>
0

精彩评论

暂无评论...
验证码 换一张
取 消