简体   繁体   中英

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

I have written a function in my .cs page. On the event onselectedindexchanged in .aspx I want to call this function.

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?

使用<%=%>标签

<%= Function() %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM