How to Call Client-Side Code Before Server-Side Event?
<asp:RadioButtonList ID="rbEmployeeGroup" runat="server" RepeatDirection="Horiz开发者_StackOverflow中文版ontal"
AutoPostBack="true" OnSelectedIndexChanged=" [Call java script to check first] then rbEmployeeGroup_SelectedIndexChanged">
<asp:ListItem Selected="True" Text="Employees" Value="employees"></asp:ListItem>
<asp:ListItem Text="Groups" Value="groups"></asp:ListItem>
</asp:RadioButtonList>
How to call the javascript function before call rbEmployeeGroup_SelectedIndexChanged this code behind function?
You need to add an onclick handler to every radiobutton in your list.
This can be done in your server code before the control is rendered.
foreach (var item in rbEmployeeGroup.Items)
{
item.Attributes.Add("onclick", "nameOfJavascriptFunction");
}
I figured out. Just add the onClientClick = "..."
When we want to execute client code first than server code then we need to use Onclientclick . show below is one example:
<asp:Button
ID="btnAlelrt"
runat="server"
Text="SubmitDetails"
OnClick="btnAlelrt_Click"
OnClientClick="return confirm('Data Already Exists ,Do you Want Update?');"
/>
精彩评论