根据在更新面板Sys.WebForms.PageRequestManagerSe中选择第一个DDL来填充DDL ... [英] Populating DDL based on selection of 1st DDL in an Update Panel Sys.WebForms.PageRequestManagerSe...

查看:72
本文介绍了根据在更新面板Sys.WebForms.PageRequestManagerSe中选择第一个DDL来填充DDL ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个asp:下拉控件.

第一个列出了一堆可用于过滤数据库的列

用户选择了要使用的列后,我想在数据库中查询一个表,该表包含基于用户选择的值列表.

我不断得到:

Microsoft JScript运行时错误:Sys.WebForms.PageRequestManagerServerErrorException:无效的回发或回调参数.使用< pages enableeventvalidation ="true">启用事件验证.在配置中或<%@页面EnableEventValidation ="true"%>在页面中.为了安全起见,此功能验证回发或回调事件的参数源自最初呈现它们的服务器控件.如果数据有效且预期,请使用ClientScriptManager.RegisterForEventValidation方法以注册回发或回调数据以进行验证.

我似乎无法找到解决问题的解决方案b/c我似乎无法确切地找出问题所在.我假设这两个下拉控件均位于同一面板中.我的页面和代码如下:

<pre lang="xml"><asp:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional">
                         <ContentTemplate>
  <%-- as planned / as built --%>
                                <asp:Table ID="tblFilters" runat="server" CellPadding="0" CellSpacing="0" CssClass="" Width="460px" >
                                     <asp:TableRow>
                                                <asp:TableCell Width="20px" HorizontalAlign="Left">
                                                    <asp:Label ID="lblMOper" Font-Bold="true" Font-Size="11px" ForeColor="Blue" runat="server"
                                                            Enabled="false" />
                                                </asp:TableCell>
                                                <asp:TableCell Wrap="false">
                                                    <asp:Label ID="lblAPAB" Font-Bold="true" Width="200px" Text="Filters" runat="server"></asp:Label>
                                                </asp:TableCell>
                                                <asp:TableCell HorizontalAlign="Right" ColumnSpan="2">
                                                    <asp:RadioButtonList runat="server" ID="rdbOperatorBottom" Font-Size="10px" AutoPostBack="True"
                                                        RepeatDirection="Horizontal" OnSelectedIndexChanged="rdbOperChangeBottom">
                                                        <asp:ListItem Selected="True" Value="and"> and</asp:ListItem>
                                                        <asp:ListItem Value="or">or</asp:ListItem>
                                                    </asp:RadioButtonList>
                                                </asp:TableCell>
                                    </asp:TableRow>
                                <asp:TableRow>
                                                    <asp:TableCell Width="20px">
                                                        <asp:Label ID="lblOper4" Text="" runat="server" Enabled="false" />
                                                    </asp:TableCell>
                                                    <asp:TableCell VerticalAlign="Top" HorizontalAlign="Right">
                                                        <asp:DropDownList ID="ddl_ColumnFilterList1" Width="200" runat="server"
                                                                    DataTextField="COLUMN_NAME"
                                                                    OnClick="fn_ddlEmpty(this)"  OnSelectedIndexChanged="FillFilterValues" AutoPostBack="true" Font-Size="8">
                                                        </asp:DropDownList>

                                                    </asp:TableCell>
                                                    <asp:TableCell HorizontalAlign="Center" VerticalAlign="Middle">
                                                        <asp:Label ID="lblEq4" Text=" = " valign="top" runat="server" Enabled="false"></asp:Label>
                                                    </asp:TableCell>
                                                    <asp:TableCell VerticalAlign="Top">
          
                                                        <asp:Label ID="lblMsg" runat="server"></asp:Label>
                                                              <asp:DropDownList ID="ddl_FilterValue1" Width="250" runat="server"  SelectionMode="Multiple"  AutoPostBack="false"
                                                                 Font-Size="8"></asp:DropDownList>

                                                    </asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow>
                                                        <asp:TableCell Width="20px" HorizontalAlign="Left" >
                                                            <asp:Label ID="lblOper5" Font-Size="9px" Text=" and     " runat="server" Enabled="false"></asp:Label>
                                                        </asp:TableCell>
                                                        <asp:TableCell VerticalAlign="Top" HorizontalAlign="Right">
                                                            <%--<asp:DropDownList ID="ddl_ColumnFilterList2" Width="200" runat="server" DataSourceID="SqlDSColumnList"
                                                                DataTextField="COLUMN_NAME" DataValueField="COLUMN_NAME" OnDataBound="ddl_ColumnFilterList2_DataBound"
                                                                OnSelectedIndexChanged="ddl_ColumnFilterList2_SelectedIndexChanged" AutoPostBack="true">
                                                            </asp:DropDownList>--%>
                                                            <asp:DropDownList ID="ddl_ColumnFilterList2" Width="200" runat="server" OnClick="fn_ddlEmpty(this)" AutoPostBack="true"   Font-Size="8" >
                                                            </asp:DropDownList>
                                                        </asp:TableCell>
                                                        <asp:TableCell>
                                                            <asp:Label ID="lblEq5" Text="=" runat="server" Enabled="false"></asp:Label>
                                                        </asp:TableCell>
                                                        <asp:TableCell VerticalAlign="Top">
                                                            <asp:DropDownList ID="ddl_FilterValue2" Width="250" runat="server"
                                                                       DataSourceID="SqlDS_UI_FilverValues"
                                                                       DataTextField="FilterValue" DataValueField="FilterValue" AutoPostBack="false"
                                                                       SelectionMode="Multiple"  Font-Size="8">
                                                        </asp:DropDownList>
                                                        </asp:TableCell>
                                    </asp:TableRow>
                                </asp:Table>
                   <%-- ad-hoc --%>
                                <asp:Table  ID="tblAdHocFilters" runat="server" CellPadding="0" CellSpacing="0" CssClass="" Width="460px" >
                                   <asp:TableRow>
                                                <asp:TableCell Width="20px" HorizontalAlign="Left">
                                                    <asp:Label ID="Label6" Font-Bold="true" Font-Size="11px" ForeColor="Blue" runat="server"
                                                            Text="or" Enabled="false" />
                                                </asp:TableCell>
                                                <asp:TableCell Wrap="false">
                                                    <asp:Label ID="Label7" Font-Bold="true" Width="200px" Text="Ad-Hoc Filters" runat="server"></asp:Label>
                                                </asp:TableCell>
                                                <asp:TableCell HorizontalAlign="Right" ColumnSpan="2">
                                                    <asp:RadioButtonList runat="server" ID="RadioButtonList1" Font-Size="10px" AutoPostBack="True"
                                                        RepeatDirection="Horizontal" OnSelectedIndexChanged="rdbOperChangeBottom">
                                                        <asp:ListItem Selected="True" Value="and"> and</asp:ListItem>
                                                        <asp:ListItem Value="or">or</asp:ListItem>
                                                    </asp:RadioButtonList>
                                                </asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow>
                                                       <asp:TableCell Width="20px" HorizontalAlign="Left" >
                                                            <asp:Label ID="Label2" Font-Size="9px" Text=" and     " runat="server" Enabled="false"></asp:Label>
                                                        </asp:TableCell>
                                                        <asp:TableCell VerticalAlign="Top" HorizontalAlign="Right">
                                                            <asp:DropDownList ID="DropDownList1" Width="200" runat="server"  AutoPostBack="true"  >
                                                                <asp:ListItem>Please choose a filter..</asp:ListItem>
                                                            </asp:DropDownList>
                                                        </asp:TableCell>
                                                        <asp:TableCell HorizontalAlign="Center" VerticalAlign="Middle">
                                                            <asp:Label ID="Label3" Text=" = " valign="top" runat="server" Enabled="false"></asp:Label>
                                                        </asp:TableCell>
                                                        <asp:TableCell VerticalAlign="Top">
                                                            <asp:TextBox ID="TextBox1" valign="top" runat="server" Width="250" Enabled="false" OnTextChanged="addCriteria" AutoPostBack="true">
                                                            </asp:TextBox>
                                                        </asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow>
                                        <asp:TableCell Width="20px" HorizontalAlign="Left" >
                                                            <asp:Label ID="Label4" Font-Size="9px" Text=" and     " runat="server" Enabled="false"></asp:Label>
                                                        </asp:TableCell>
                                        <asp:TableCell VerticalAlign="Top" HorizontalAlign="Right">
                                            <asp:DropDownList ID="DropDownList2" Width="200" runat="server"  AutoPostBack="true"  >
                                                <asp:ListItem>Please choose a filter..</asp:ListItem>
                                            </asp:DropDownList>
                                        </asp:TableCell>
                                        <asp:TableCell HorizontalAlign="Center" VerticalAlign="Middle">
                                            <asp:Label ID="Label5" Text=" = " valign="top" runat="server" Enabled="false"></asp:Label>
                                        </asp:TableCell>
                                        <asp:TableCell VerticalAlign="Top">
<%--
                                            <ig:WebTextEditor ID="TextBox4" runat="server" Enabled="false"
                                                              Width="250px" OnTextChanged="addCriteria" AutoPostBackFlags-ValueChanged="Async"
                                                              Height="17px">
                                            </ig:WebTextEditor>
   --%>
                                            <asp:TextBox ID="TextBox2" valign="top" runat="server" Width="250" Enabled="false" OnTextChanged="addCriteria" AutoPostBack="true">
                                            </asp:TextBox>
                                        </asp:TableCell>
                                    </asp:TableRow>
                                </asp:Table>
                    </ContentTemplate>
                    <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="ddl_ColumnFilterList1" EventName="SelectedIndexChanged" />
                        </Triggers>

                    </asp:UpdatePanel


>




背后的代码:

protected void ddl_ColumnFilterList1_selectedindexchanged(object sender, EventArgs e)
  {
      if (ddl_ColumnFilterList1.SelectedIndex == 0)
      {
          Alert.Show("You must select columns to continue.");
          return;
      }

      string COLUMN_NAME = "''" + ddl_ColumnFilterList1.SelectedValue.ToString() + "''";

      ddl_FilterValue1.Items.Add(FillFilterValues(COLUMN_NAME));
      ddl_FilterValue1.DataBind();

  }



以防万一,这里是第一个下拉菜单的on click事件的javascript,它可以正常工作:

    function fn_ddlEmpty(ddl) {

    if (ddl.options.length == 0) {
        alert("Please select columns on the right for your Report in order to choose a filter.");
    }
}


解决方案

请在代码块中发布代码,这样实际上是不可读的!您可以通过点击编辑器顶部的代码块链接或使用< pre>和</pre> ;.

如果您只是想解决错误,请禁用EventValidation(就像读取错误消息一样).我不知道这是否真的可以解决您的问题(或者只是消除症状).

只需更改您的Page指令

<%@Page EnableEventValidation="false" ...%>


请注意,这可能会带来很大的安全风险! .我真的不想禁用验证.


if (_this._xmlHttpRequest.readyState === 4 ) {
           try {
               if (typeof(_this._xmlHttpRequest.status) === "undefined") {
                   return;
               }
           }
           catch(ex) {
               return;
           }

           _this._clearTimer();
           _this._responseAvailable = true;
           try {
               _this._webRequest.completed(Sys.EventArgs.Empty);
           }
           finally {
               if (_this._xmlHttpRequest != null) {
                   _this._xmlHttpRequest.onreadystatechange = Function.emptyMethod;
                   _this._xmlHttpRequest = null;
               }
           }
       }


I have 2 asp:Drop down controls.

The first lists a bunch of columns available to choose to filter a database

Once the user selected the column they want to use, I want to query a table in my database that holds a list of values based upon the user selection.

I keep getting:

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: 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.

I can''t seem to find a solution to fix the problem b/c I can''t seem to exactly figure out what the problem is. I''m assuming it''s b/c both dropdown controls are within the same panel. My page and code behind is below:

<pre lang="xml"><asp:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional">
                         <ContentTemplate>
  <%-- as planned / as built --%>
                                <asp:Table ID="tblFilters" runat="server" CellPadding="0" CellSpacing="0" CssClass="" Width="460px" >
                                     <asp:TableRow>
                                                <asp:TableCell Width="20px" HorizontalAlign="Left">
                                                    <asp:Label ID="lblMOper" Font-Bold="true" Font-Size="11px" ForeColor="Blue" runat="server"
                                                            Enabled="false" />
                                                </asp:TableCell>
                                                <asp:TableCell Wrap="false">
                                                    <asp:Label ID="lblAPAB" Font-Bold="true" Width="200px" Text="Filters" runat="server"></asp:Label>
                                                </asp:TableCell>
                                                <asp:TableCell HorizontalAlign="Right" ColumnSpan="2">
                                                    <asp:RadioButtonList runat="server" ID="rdbOperatorBottom" Font-Size="10px" AutoPostBack="True"
                                                        RepeatDirection="Horizontal" OnSelectedIndexChanged="rdbOperChangeBottom">
                                                        <asp:ListItem Selected="True" Value="and"> and</asp:ListItem>
                                                        <asp:ListItem Value="or">or</asp:ListItem>
                                                    </asp:RadioButtonList>
                                                </asp:TableCell>
                                    </asp:TableRow>
                                <asp:TableRow>
                                                    <asp:TableCell Width="20px">
                                                        <asp:Label ID="lblOper4" Text="" runat="server" Enabled="false" />
                                                    </asp:TableCell>
                                                    <asp:TableCell VerticalAlign="Top" HorizontalAlign="Right">
                                                        <asp:DropDownList ID="ddl_ColumnFilterList1" Width="200" runat="server"
                                                                    DataTextField="COLUMN_NAME"
                                                                    OnClick="fn_ddlEmpty(this)"  OnSelectedIndexChanged="FillFilterValues" AutoPostBack="true" Font-Size="8">
                                                        </asp:DropDownList>

                                                    </asp:TableCell>
                                                    <asp:TableCell HorizontalAlign="Center" VerticalAlign="Middle">
                                                        <asp:Label ID="lblEq4" Text=" = " valign="top" runat="server" Enabled="false"></asp:Label>
                                                    </asp:TableCell>
                                                    <asp:TableCell VerticalAlign="Top">
          
                                                        <asp:Label ID="lblMsg" runat="server"></asp:Label>
                                                              <asp:DropDownList ID="ddl_FilterValue1" Width="250" runat="server"  SelectionMode="Multiple"  AutoPostBack="false"
                                                                 Font-Size="8"></asp:DropDownList>

                                                    </asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow>
                                                        <asp:TableCell Width="20px" HorizontalAlign="Left" >
                                                            <asp:Label ID="lblOper5" Font-Size="9px" Text=" and     " runat="server" Enabled="false"></asp:Label>
                                                        </asp:TableCell>
                                                        <asp:TableCell VerticalAlign="Top" HorizontalAlign="Right">
                                                            <%--<asp:DropDownList ID="ddl_ColumnFilterList2" Width="200" runat="server" DataSourceID="SqlDSColumnList"
                                                                DataTextField="COLUMN_NAME" DataValueField="COLUMN_NAME" OnDataBound="ddl_ColumnFilterList2_DataBound"
                                                                OnSelectedIndexChanged="ddl_ColumnFilterList2_SelectedIndexChanged" AutoPostBack="true">
                                                            </asp:DropDownList>--%>
                                                            <asp:DropDownList ID="ddl_ColumnFilterList2" Width="200" runat="server" OnClick="fn_ddlEmpty(this)" AutoPostBack="true"   Font-Size="8" >
                                                            </asp:DropDownList>
                                                        </asp:TableCell>
                                                        <asp:TableCell>
                                                            <asp:Label ID="lblEq5" Text="=" runat="server" Enabled="false"></asp:Label>
                                                        </asp:TableCell>
                                                        <asp:TableCell VerticalAlign="Top">
                                                            <asp:DropDownList ID="ddl_FilterValue2" Width="250" runat="server"
                                                                       DataSourceID="SqlDS_UI_FilverValues"
                                                                       DataTextField="FilterValue" DataValueField="FilterValue" AutoPostBack="false"
                                                                       SelectionMode="Multiple"  Font-Size="8">
                                                        </asp:DropDownList>
                                                        </asp:TableCell>
                                    </asp:TableRow>
                                </asp:Table>
                   <%-- ad-hoc --%>
                                <asp:Table  ID="tblAdHocFilters" runat="server" CellPadding="0" CellSpacing="0" CssClass="" Width="460px" >
                                   <asp:TableRow>
                                                <asp:TableCell Width="20px" HorizontalAlign="Left">
                                                    <asp:Label ID="Label6" Font-Bold="true" Font-Size="11px" ForeColor="Blue" runat="server"
                                                            Text="or" Enabled="false" />
                                                </asp:TableCell>
                                                <asp:TableCell Wrap="false">
                                                    <asp:Label ID="Label7" Font-Bold="true" Width="200px" Text="Ad-Hoc Filters" runat="server"></asp:Label>
                                                </asp:TableCell>
                                                <asp:TableCell HorizontalAlign="Right" ColumnSpan="2">
                                                    <asp:RadioButtonList runat="server" ID="RadioButtonList1" Font-Size="10px" AutoPostBack="True"
                                                        RepeatDirection="Horizontal" OnSelectedIndexChanged="rdbOperChangeBottom">
                                                        <asp:ListItem Selected="True" Value="and"> and</asp:ListItem>
                                                        <asp:ListItem Value="or">or</asp:ListItem>
                                                    </asp:RadioButtonList>
                                                </asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow>
                                                       <asp:TableCell Width="20px" HorizontalAlign="Left" >
                                                            <asp:Label ID="Label2" Font-Size="9px" Text=" and     " runat="server" Enabled="false"></asp:Label>
                                                        </asp:TableCell>
                                                        <asp:TableCell VerticalAlign="Top" HorizontalAlign="Right">
                                                            <asp:DropDownList ID="DropDownList1" Width="200" runat="server"  AutoPostBack="true"  >
                                                                <asp:ListItem>Please choose a filter..</asp:ListItem>
                                                            </asp:DropDownList>
                                                        </asp:TableCell>
                                                        <asp:TableCell HorizontalAlign="Center" VerticalAlign="Middle">
                                                            <asp:Label ID="Label3" Text=" = " valign="top" runat="server" Enabled="false"></asp:Label>
                                                        </asp:TableCell>
                                                        <asp:TableCell VerticalAlign="Top">
                                                            <asp:TextBox ID="TextBox1" valign="top" runat="server" Width="250" Enabled="false" OnTextChanged="addCriteria" AutoPostBack="true">
                                                            </asp:TextBox>
                                                        </asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow>
                                        <asp:TableCell Width="20px" HorizontalAlign="Left" >
                                                            <asp:Label ID="Label4" Font-Size="9px" Text=" and     " runat="server" Enabled="false"></asp:Label>
                                                        </asp:TableCell>
                                        <asp:TableCell VerticalAlign="Top" HorizontalAlign="Right">
                                            <asp:DropDownList ID="DropDownList2" Width="200" runat="server"  AutoPostBack="true"  >
                                                <asp:ListItem>Please choose a filter..</asp:ListItem>
                                            </asp:DropDownList>
                                        </asp:TableCell>
                                        <asp:TableCell HorizontalAlign="Center" VerticalAlign="Middle">
                                            <asp:Label ID="Label5" Text=" = " valign="top" runat="server" Enabled="false"></asp:Label>
                                        </asp:TableCell>
                                        <asp:TableCell VerticalAlign="Top">
<%--
                                            <ig:WebTextEditor ID="TextBox4" runat="server" Enabled="false"
                                                              Width="250px" OnTextChanged="addCriteria" AutoPostBackFlags-ValueChanged="Async"
                                                              Height="17px">
                                            </ig:WebTextEditor>
   --%>
                                            <asp:TextBox ID="TextBox2" valign="top" runat="server" Width="250" Enabled="false" OnTextChanged="addCriteria" AutoPostBack="true">
                                            </asp:TextBox>
                                        </asp:TableCell>
                                    </asp:TableRow>
                                </asp:Table>
                    </ContentTemplate>
                    <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="ddl_ColumnFilterList1" EventName="SelectedIndexChanged" />
                        </Triggers>

                    </asp:UpdatePanel


>




Code behind:

protected void ddl_ColumnFilterList1_selectedindexchanged(object sender, EventArgs e)
  {
      if (ddl_ColumnFilterList1.SelectedIndex == 0)
      {
          Alert.Show("You must select columns to continue.");
          return;
      }

      string COLUMN_NAME = "''" + ddl_ColumnFilterList1.SelectedValue.ToString() + "''";

      ddl_FilterValue1.Items.Add(FillFilterValues(COLUMN_NAME));
      ddl_FilterValue1.DataBind();

  }



Just in case, here is the javascript for the on click event of the 1st dropdown which works fine:

    function fn_ddlEmpty(ddl) {

    if (ddl.options.length == 0) {
        alert("Please select columns on the right for your Report in order to choose a filter.");
    }
}


Any help would be great!

解决方案

Please post code in a code block, it is virtually unreadable like this! You can do that by clicking the code block link at the top of the editor or by surrounding the code with <pre> and </pre>.

If you just want to turn of the error... disable EventValidation (just like the error message reads). I don''t know if that really solves your problem (or just shuts off a symptom).

Just change your Page directive

<%@Page EnableEventValidation="false" ...%>


Please be aware, that this might introtduce a big security risk!


I tried that just to see if it would stop the error which it did but then it wasn''t populating the dropdown either. I don''t really want to disable validation.


if (_this._xmlHttpRequest.readyState === 4 ) {
           try {
               if (typeof(_this._xmlHttpRequest.status) === "undefined") {
                   return;
               }
           }
           catch(ex) {
               return;
           }

           _this._clearTimer();
           _this._responseAvailable = true;
           try {
               _this._webRequest.completed(Sys.EventArgs.Empty);
           }
           finally {
               if (_this._xmlHttpRequest != null) {
                   _this._xmlHttpRequest.onreadystatechange = Function.emptyMethod;
                   _this._xmlHttpRequest = null;
               }
           }
       }


这篇关于根据在更新面板Sys.WebForms.PageRequestManagerSe中选择第一个DDL来填充DDL ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆