Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 单选按钮列表事件未始终触发_C#_Asp.net_Radiobuttonlist - Fatal编程技术网

C# 单选按钮列表事件未始终触发

C# 单选按钮列表事件未始终触发,c#,asp.net,radiobuttonlist,C#,Asp.net,Radiobuttonlist,我有一个非常奇怪的问题,单选按钮列表工作正常,但单击几下后,它似乎不会触发SelectedIndexChanged事件,只是在回发后保持相同的值 <asp:RadioButtonList runat="server" ID="rblShowRecords" AutoPostBack="true" OnSelectedIndexChanged="rblShowRecords_SelectedIndexChanged" RepeatDirection="Horizontal">

我有一个非常奇怪的问题,单选按钮列表工作正常,但单击几下后,它似乎不会触发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>  
我不明白为什么它只精确地工作了3次,但之后,它就再也没有进入上面的方法

使用dropdownlist尝试相同的操作,也可以工作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
回发或回调参数无效。在配置或页面中使用启用事件验证。出于安全目的,此功能验证回发或回调事件的参数是否源自最初呈现它们的服务器控件。如果数据有效且符合要求,请使用ClientScriptManager.RegisterForEventValidation方法注册回发或回调数据以进行验证

根据您的上一条评论,删除将SQL查询设置为SelectedItem.Value的代码,并在需要时使用SelectedItem.Text属性获取命令,当您为最后一行代码中的项设置值时,select查询可能包含类似于
的字符,您正在尝试将SQL查询设置为项值,并且SQL查询可能包含将导致无效回发的字符。您已经知道要基于文本检索哪个select命令,那么为什么要尝试将select查询设置为dropdownlist?好的,selected.item.text是您在DDL中看到的,selected.item.value是保存在配置文件中的字符串sql查询。但是为什么它工作了3次却失败了?是的,但是为什么要将它设置为Selected.item.Value?您可能有一个查询包含字符,如
,基本上,如果(IsPostBack){CEDatabaseSource.SelectCommand=ddlShowRecords.SelectedValue;CEDatabaseSource.DataBind();},我需要在页面加载
中执行此操作
否则,当我有一个特定的视图并单击一行对其进行编辑时,gridview会调用默认的select命令并将一切搞糟
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
string GetCommand()
{
    switch (rblShowRecords.SelectedItem.Text)
    {
        case "Show Active/Completed":
            return ConfigurationManager.AppSettings["SelectAllRecords"].ToString();
        case "Show Active":
            return  ConfigurationManager.AppSettings["SelectActiveRecords"].ToString();
        case "Show Completed":
            return  ConfigurationManager.AppSettings["SelectCompletedRecords"].ToString();
        default:
            return "";
    }
}
if (IsPostBack) 
{ 
    CEDatabaseSource.SelectCommand = GetCommand();
    CEDatabaseSource.DataBind(); 
}
protected void rblShowRecords_SelectedIndexChanged(object sender, EventArgs e)
{
    CEDatabaseSource.SelectCommand = GetCommand();
    CEDatabaseSource.DataBind(); //Commit the changes to the data source.
    gvRecordList.DataBind(); //Update the GridView
}