我有很多单选按钮:
<asp:RadioButtonList ID="selectedYesNoQuestionBlock1" runat="server" RepeatDirection="Horizontal"
OnSelectedIndexChanged="Question1GotAnswered" AutoPostBack="true">
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="0"></asp:ListItem>
</asp:RadioButtonList>
<asp:RadioButtonList ID="selectedYesNoQuestionBlock2" runat="server" RepeatDirection="Horizontal"
AutoPostBack="true" OnSelectedIndexChanged="Question2GotAnswered">
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="0"></asp:ListItem>
</asp:RadioButtonList>
等
对于每个单选按钮,我有他们的方法:
protected void Question1GotAnswered(object sender, EventArgs e)
{}
我希望在调用方法Question1GotAnswered()之前在Page_Load中对此做出反应。我想尝试但一切都不成功。
试过这样的事情:
protected void Page_Load(object sender, EventArgs e)
{
if (sender.ToString() == "Question1GotAnswered")
{}
}
请帮助我需要它!
答案 0 :(得分:3)
唯一的方法是检查if (Request.Form["__EVENTTARGET"] == control.ClientID) { }
以查看控件回发是否是导致回发的给定控件。所以这应该是导致回发的单选按钮的ID。
HTH。