1

我有一个带有单选按钮的下拉列表。单选按钮用于对 DropDownList 进行排序(按名称、按 id 等)。数据库通过存储过程填充 DropDownList。它被一个更新面板包围。

    <div id="casefiles">
    <ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />
  <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
            <ContentTemplate>
                <div id="rbfileByHolder" runat="server">
                    <label>Sort By</label>
                    <span><asp:RadioButton class="aspRBs" GroupName="rbfileByNameOrID" ID="rbMyFiles" Text="My Files" Checked="true"
                        runat="server" AutoPostBack="True" OnCheckedChanged="rbMyFiles_CheckedChanged" /></span>
                    <span><asp:RadioButton class="aspRBs" GroupName="rbfileByNameOrID" id="rbByFileID"
                        Text="By File ID"  runat="server" AutoPostBack="True"
                        oncheckedchanged="rbByFileID_CheckedChanged" /></span>
                    <span><asp:RadioButton class="aspRBs" GroupName="rbfileByNameOrID" id="rbByFileName"
                        Text="By File Name" runat="server" AutoPostBack="True"
                        oncheckedchanged="rbByFileName_CheckedChanged" /></span>            

                </div><br />
            </ContentTemplate>
        </asp:UpdatePanel>
    <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <label>Select New CaseFile</label>
                <asp:DropDownList runat="server" ID="ddlCaseFiles" DataSourceID="dsMyCaseFiles" DataTextField="Display" DataValueField="FileID" OnPreRender="ddl_PreRender" Width="524px" />
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="ddlCaseFiles" ToolTip="Casefile Required" InitialValue="-1" Text="*" Display="Dynamic" />
                <ajaxToolkit:ListSearchExtender ID="ddlExtCaseFiles" runat="server" PromptCssClass="ListSearchExtenderPrompt" TargetControlID="ddlCaseFiles" BehaviorID="ddlExtCaseFiles" Enabled="True"/>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="rbByFileName" EventName="CheckedChanged" />
                <asp:AsyncPostBackTrigger ControlID="rbByFileID" EventName="CheckedChanged" />
                <asp:AsyncPostBackTrigger ControlID="rbMyFiles" EventName="CheckedChanged" />
            </Triggers>
        </asp:UpdatePanel>
        </div>

这是我的 javascript 函数,用于在弹出窗口中显示控件:

//create popup with dropdownLists then call moveCaseFile
    function getCaseFiles(canCopyTo) {
        //create Popup with content from div
        $('#casefiles').dialog({
            autoOpen: true,
            height: 'auto',
            width: 'auto',
            modal: true,
            buttons: {
                "Ok": function () {
                    debugger;
                    alert("test");
                    var t = $("#casefiles");
                },
                Cancel: function () {
                    $(this).dialog('close');
                    $("#viewExpensesGrid").flexReload();
                }
            }
        });
    }

这是后面的相关代码(单选按钮排序和为下拉列表分配默认值):

protected void rbByFileName_CheckedChanged(object sender, EventArgs e)
{
    ddlCaseFiles.DataSourceID = "dsCaseFilesReverse";
    ddlCaseFiles.DataTextField = "Display";
    ddlCaseFiles.DataValueField = "FileID";
}

protected void rbByFileID_CheckedChanged(object sender, EventArgs e)
{
    ddlCaseFiles.DataSourceID = "dsCaseFiles";
    ddlCaseFiles.DataTextField = "Display";
    ddlCaseFiles.DataValueField = "FileID";
}

protected void rbMyFiles_CheckedChanged(object sender, EventArgs e)
{
    ddlCaseFiles.DataSourceID = "dsMyCaseFiles";
    ddlCaseFiles.DataTextField = "Display";
    ddlCaseFiles.DataValueField = "FileID";
}
protected void ddl_PreRender(object sender, EventArgs e)
{
    DropDownList ddl = (DropDownList)sender;
    try
    {
        if (ddl.Items[0].Value != "-1")
            ddl.Items.Insert(0, new ListItem("--Select--", "-1"));
    }
    catch
    {
        ddl.Items.Insert(0, new ListItem("--Select--", "-1"));
    }
}

好的。是时候解释更多了。

假设会出现一个弹出窗口,如下所示:![在此处输入图像描述][1]

如果您单击 myFiles,它将对显示您拥有的所有文件的下拉列表进行排序(通过存储过程)。因此,对于每个单选按钮,它会根据不同的信息(通过存储过程)进行不同的排序。但我的问题是,当我选择一个单选按钮(并且它必须执行存储的过程)时,我收到此错误:

未捕获的 Sys.WebForms.PageRequestManagerServerErrorException:Sys.WebForms.PageRequestManagerServerErrorException:处理服务器上的请求时发生未知错误。服务器返回的状态码是:404

我认为搞砸的是UpdatePanel/AutoPostback。它不仅更新下拉列表,还尝试刷新页面,但刷新到另一个链接或其他内容。请在小猫被踢之前帮忙

这是我从 chrome 调试器得到的错误:

未捕获的 Sys.WebForms.PageRequestManagerServerErrorException:Sys.WebForms.PageRequestManagerServerErrorException:处理服务器上的请求时发生未知错误。服务器返回的状态码是:404

所有这些错误都是在我添加 AutoPostback="true" 时发生的。

4

0 回答 0