我有一个非常奇怪的单选按钮列表问题,它可以正常工作,但点击几下后它似乎没有触发 SelectedIndexChanged 事件,并且在回发后保持相同的值。
<asp:RadioButtonList runat="server" ID="rblShowRecords" AutoPostBack="true"
OnSelectedIndexChanged="rblShowRecords_SelectedIndexChanged" RepeatDirection="Horizontal">
<asp:ListItem >Show Active/Completed</asp:ListItem>
<asp:ListItem >Show Active</asp:ListItem>
<asp:ListItem >Show Completed</asp:ListItem>
</asp:RadioButtonList>
这是事件方法:
protected void rblShowRecords_SelectedIndexChanged(object sender, EventArgs e)
{
switch (rblShowRecords.SelectedItem.Text)
{
case "Show Active/Completed":
CEDatabaseSource.SelectCommand = ConfigurationManager.AppSettings["SelectAllRecords"].ToString();//"SELECT * FROM [CERecord] ORDER BY [Priority]";
break;
case "Show Active":
CEDatabaseSource.SelectCommand = ConfigurationManager.AppSettings["SelectActiveRecords"].ToString();
break;
case "Show Completed":
CEDatabaseSource.SelectCommand = ConfigurationManager.AppSettings["SelectCompletedRecords"].ToString();
break;
default:
break;
}
CEDatabaseSource.DataBind(); //Commit the changes to the data source.
gvRecordList.DataBind(); //Update the GridView
rblShowRecords.SelectedItem.Value = CEDatabaseSource.SelectCommand; //Update the value of the selected radio button with the selected SELECT command.
}
我不明白为什么它只能精确工作 3 次,但之后,它就再也没有进入上述方法。
尝试相同的事情但使用下拉列表,也可以工作 3 次,然后出现此错误:
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation