+ Reply to Thread
Results 1 to 6 of 6

Thread: Cascading Drop Down Lists Invalid Postback or Callback argument Error

  1. #1
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Cascading Drop Down Lists Invalid Postback or Callback argument Error

    I was playing around with the AJAX Control Toolkit CascadingDropDown extender. I set it up to use a webservice method to populate the contents. Everything worked perfectly until I triggered an event that caused a post back. This is when I received the following error:

    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.
    Basically, it is saying that you either have to turn event validation off for the page or register it with event validation. Well, turning off event validation for the page is not an option in my book. That poses a serious security risk.

    So I tried registering it with the ClientScriptManager and fed it every possible value for the drop down lists I had on my page. This DID NOT work either.

    The solution I found, posted by another person with the same problem, was to override the render method and databind all possible values for the drop down lists.

    So, in my code for the page:

    Code:
    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
        With Me.DropDownList1
            .DataSource = myDataSource
            .DataTextField = "mydatatextfield"
            .DataValueField = "mydatavaluefield"
            .DataBind()
        End With
     
        MyBase.Render(writer)
    End Sub
    
    Above, DropDownList1 is the TargetControlID of the CascadingDropDown. That was it! Any postback event on my page no longer triggered the error.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  2. #2
    Barn Newbie nilact is an unknown quantity at this point nilact's Avatar
    Join Date
    Dec 2009
    Posts
    1
    Rep Power
    3

    Hello,

    I saw the same solution at different places on internet. But what would i write in datasource of Dropdownlist?? As Cascadingdropdown (Ajax Control itself) calls webservice to fill up the dropdown??

    Proper Explaination will be appreciated. Thanks

  3. #3
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    In my case, I have a Business class that my web method calls to get the data. I use this same business class to get the data in the overrided method:
    Code:
    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
        Dim myDataSource As System.Collections.Generic.List(Of MyClass) = MyClass.GetData
        With Me.DropDownList1
            .DataSource = myDataSource
            .DataTextField = "mydatatextfield"
            .DataValueField = "mydatavaluefield"
            .DataBind()
        End With
     
        MyBase.Render(writer)
    End Sub
    
    If you don't have something like this, then you should be able to call your web method in the overrided render method or duplicate the code to get the data.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  4. #4
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Do you need to just include this in the page that has client populated dropdown?

    And do you need to do anything about the other controls on the page? Or just include the client populated control?

    I also tried the ClientScript.RegisterForEventValidation method in Page_Render and it didn't help.

  5. #5
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    OK. I've answered my own questions...
    1) Yes.
    2) No. Just include the base.render statement

    C# version for those that need it
    Code:
        protected override void Render(HtmlTextWriter writer)
        {
            this.ddlReceptor.DataSource = Receptor.GetAllReceptorList();
            this.ddlReceptor.DataValueField = "id";
            this.ddlReceptor.DataBind();
            this.ddlReceptor.Items.Add(new ListItem("None", "0"));
            base.Render(writer);
        }
    
    Also need to ensure you add all possible values. For example, I manually add a "None" option to all the returned possibilities, so I also need to add it in the render event.

    Hope that helps.

  6. #6
    Barn Newbie leethams is an unknown quantity at this point leethams's Avatar
    Join Date
    Apr 2010
    Posts
    1
    Rep Power
    2

    A different solution

    I was struggling with this same problem and found someone who tracked down the real problem and came up with a clean solution. Basically you just subclass the DropDownList control without adding any changes to it. But since your control won't be decorated with SupportsEventValidation, it won't participate in the event validation that the page is doing.

    The forum won't let me post a URL to the blog entry, but if you replace the [dot] with real dots, you should be able to go read it. johanleino[dot]wordpress[dot]com/2009/11/17/cascadingdropdown-casues-invalid-postback-or-callback-argument-error/

+ Reply to Thread

Similar Threads

  1. Object Reference Error on Custom Control Postback
    By richyrich in forum .NET Development
    Replies: 1
    Last Post: September 22nd, 2008, 06:56 PM
  2. drop down problem
    By todd2006 in forum ASP Development
    Replies: 2
    Last Post: July 24th, 2008, 02:55 PM
  3. Retrieving DataItem on Postback
    By richyrich in forum .NET Development
    Replies: 4
    Last Post: July 21st, 2008, 11:15 AM
  4. Finding Datalist Row on auto postback
    By richyrich in forum .NET Development
    Replies: 1
    Last Post: May 12th, 2008, 05:52 AM
  5. Cascading List Filters
    By AOG123 in forum Access Database Samples
    Replies: 0
    Last Post: May 6th, 2008, 12:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO