Click here to Skip to main content
15,889,887 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
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!
Posted
Updated 10-Jun-11 11:31am
v4
Comments
weixight 7-Jul-13 4:26am    
The solution you describe above is fantastic. I want to know if the page will not do postback

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!
 
Share this answer
 
v3
Comments
weixight 7-Jul-13 9:19am    
"Microsoft JScript runtime error: Unable to get value of the property 'ctl00_ContentPlaceHolder1_ddllga': object is null or undefined". Can anyone help me to resolve this message on javascript page
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.
 
Share this answer
 
Comments
Morl99 10-Jun-11 17:13pm    
Yeah I was guessing that this will not really fix the problem. Please edit your first question and wrap the code in <pre> tags. Otherwise I (and most other people) will refuse to help you. And for future reference, it is better to write answers to follow up questions either as an edit in the original question or as a comment to that solution. Do not post it as a seperate solution. This will become very chaotic after a while.
Morl99 10-Jun-11 19:49pm    
Ok there you go. It is still not really readable, but that is either the websites or my browsers fault (tabs are very spacy). I can't immediately point to the problem. I have seen this error, when I tried to call an ASP.NET Function out of the client code. I don't see you doing that here (is there any JavaScript code missing maybe?).

Maybe it is a totally different problem. Could you try commenting out all the update panel stuff, you don't really need that for trying it out, full rendering works just as well. Oh and btw, you do have a Scriptmanager somewhere, right?

Yu can also try debugging the event handler for selected index changed, does it fire? Or does the error occur before that?
Cathryn Crane 10-Jun-11 20:57pm    
Yeah, sorry about that. I tried to fix the code but I didn't do a very good job. There's a lot there.

In answer to the javascript code, no there isn't any missing and I've tried coding on the client side and the code behind. I get the same error.

I tried commenting out the update panel and contenttemplate -- that was a good idea but I still got the same error unfortunately.

I'll post the dynamic code that it gets hung up at and see if that helps.

I've also got the following override for both dropdown objects
<pre>
protected void Page_Render(object sender, EventArgs e)
{
Page.ClientScript.RegisterForEventValidation("ddl_ColumnFilterList1");
Page.ClientScript.RegisterForEventValidation("ddl_FilterValue1");
}
</pre>
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;
               }
           }
       }
 
Share this answer
 
Comments
Morl99 12-Jun-11 18:33pm    
Mh that generated Client code isn't really helping, probably would need an expert to figure it out this way.

Maybe you have two problems here? One that causes the PageValidation Error, and one that hinders your second dropbox from beeing filled correctly? Did you try setting a breakpoint at the beginning of the event handler ddl_ColumnFilterList1_selectedindexchanged? Do that and turn the eventValidation off for testing again. Is it firing?

I don't see a reason in your markup, why it shouldn't fire the selectedIndexChanged Event.

I'm quite sorry that I can't be of more help here...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900