Event Validation in ASP.Net 2.0 Ajax

Last post 05-28-2008 6:49 AM by pareshjagatia. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 04-30-2008 3:37 AM

    Event Validation in ASP.Net 2.0 Ajax

    Hi,

    I have been receiving this error:

    " Invalid postback or callback argument. Event validation is enabled using 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.  "

    This has only been experienced by users who have been using the website whilst the same page has been updated.  It has been reported occasionally during busy times too.  The problem arises from a asp.net 2.0 drop-down control that is in an Ajax Update Panel (i.e., when a user selects an item from it).  But, it only occurs in the scenario I have described.

    This occurs usually from users using Firefox, though it has occurred sometimes with IE7 users.  However, I can only recreate the problem in Firefox. 

    I've tried a number of possible solutions using the ClientScriptManager.RegisterForEventValidation, but none have solved this problem.  Changing <%@ Page EnableEventValidation = "false" %> has temporarily solved the problem, but I don't really want this solution long term.

    The project is an ASP.Net 2.0 AJAX enabled website.  It uses masterpages.

    I'd also be interested if anyone knows more about when these errors occur, how to cater for them and if they can be trapped before a message appears in the browser.  I'd like to understand this more and what causes the error. 

    Any help on this appreciated.

    Thanks - Darren


    dbrook007
  •  Advertisement

    Featured Advertisement

     
  • 04-30-2008 8:51 AM In reply to

    • sonu
    • Top 10 Contributor
    • Joined on 05-22-2006
    • Montreal / Canada
    • Slacker
    • Points 12,183
    • MVP

    Re: Event Validation in ASP.Net 2.0 Ajax

    Did you placed the RegisterForEventValidation in the OnRender event?

    [MVP since 2005] [MCAD]
    Webmaster of DotNetSlackers
    Question or Suggestion?
    Feel free to ask my any .NET question
    Our Posting FAQ
  • 04-30-2008 9:36 AM In reply to

    Re: Event Validation in ASP.Net 2.0 Ajax

    Hi,

    Yes.... well, I think so at least...

    However, I could only find a method called "Render()" to override (I'm using C# and ASP.Net 2.0).  Is this the same thing?

    I could not find an OnRender() method... ??? 

    Anyway, I tried this: - 

    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    {  

        ClientScript.RegisterForEventValidation("BuyLetDropDown", "Select..."); 

        base.Render(writer);
    }

    ...which did not work, so I also tried this:

    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    {  

        ClientScript.RegisterForEventValidation(BuyLetDropDown.UniqueID, "Select..."); 

        base.Render(writer);
    }

    ...which also did NOT solve the problem. 

    So I tried: -

    protected override void OnRender(System.Web.UI.HtmlTextWriter writer)

    {
        ClientScript.RegisterForEventValidation("BuyLetDropDown", "Select...");
        ClientScript.RegisterForEventValidation(BuyLetDropDown.UniqueID.ToString(), "Select...");

        Register(this);

        base.Render(writer);
    }

    private void Register(Control ctrl)
    {
        foreach (Control c in ctrl.Controls)
            Register(c);

        Page.ClientScript.RegisterForEventValidation(ctrl.UniqueID);
    }

    This also did NOT work.

    I tried these methods as I'd seen this done in examples on the internet.  However, this is only a problem as described - i.e., only in that scenario and only with Firefox.

    I still don't know much about what causes it etc and the solutions I've seen offerred by various websites, books and on the MSDN don't work in my case.  It's one of these annoying problems that add silly amounts of time whilst trying to find a solution.  It also gets you down as a developer.  The workaround I used works but is far from ideal and not a long term solution.  Any help or ideas appreciated.

    Thanks - Darren 

     

    dbrook007
  • 04-30-2008 9:42 AM In reply to

    • sonu
    • Top 10 Contributor
    • Joined on 05-22-2006
    • Montreal / Canada
    • Slacker
    • Points 12,183
    • MVP

    Re: Event Validation in ASP.Net 2.0 Ajax

    Try:

    protected override void Render(HtmlTextWriter writer)
    {
      Page.ClientScript.RegisterForEventValidation(BuyLetDropDown.UniqueID, this.ToString());
      base.Render(writer);
    }

    [MVP since 2005] [MCAD]
    Webmaster of DotNetSlackers
    Question or Suggestion?
    Feel free to ask my any .NET question
    Our Posting FAQ
  • 05-01-2008 5:53 AM In reply to

    Re: Event Validation in ASP.Net 2.0 Ajax

    Hi,

    Thanks for replying.  I tried it but unfortunately it did not work.  Sad

    ...Darren 

    dbrook007
  • 05-01-2008 9:12 AM In reply to

    • sonu
    • Top 10 Contributor
    • Joined on 05-22-2006
    • Montreal / Canada
    • Slacker
    • Points 12,183
    • MVP

    Re: Event Validation in ASP.Net 2.0 Ajax

    Send me the project please to my email and I will look at it.  

    [MVP since 2005] [MCAD]
    Webmaster of DotNetSlackers
    Question or Suggestion?
    Feel free to ask my any .NET question
    Our Posting FAQ
  • 05-01-2008 9:32 AM In reply to

    Re: Event Validation in ASP.Net 2.0 Ajax

    Hi Sonu,

    I can't send the project unfortunately as I'm bound by a confidentiality contract that prevents me from releasing the project or any source code.

    Sadly, this may be an instance where the temporary solution, though far from ideal, becomes the permanent one.

    I don't really have an understanding of why the problem is occuring but time is becoming a big pressure now.  I'd  like to recreate the problem in an example site but unfortunately, I just don't have the time..... it's very frustrating and a problem.

    I may have to just go with changing the page directive I referred to previously... not ideal but I need to keep things moving forward now.

    argggh.  Very frustrating.

    Thank you for your help.

    ....Darren 

    dbrook007
  • 05-01-2008 9:38 AM In reply to

    • sonu
    • Top 10 Contributor
    • Joined on 05-22-2006
    • Montreal / Canada
    • Slacker
    • Points 12,183
    • MVP

    Re: Event Validation in ASP.Net 2.0 Ajax

    I am very sorry to hear about that. I will try to do some research about this and let you know. In the meanwhile use the solution that works for you. See it from this point: at least the application is not broken and works!  

    [MVP since 2005] [MCAD]
    Webmaster of DotNetSlackers
    Question or Suggestion?
    Feel free to ask my any .NET question
    Our Posting FAQ
  • 05-02-2008 3:48 AM In reply to

    Re: Event Validation in ASP.Net 2.0 Ajax

    Hi,

    Thanks for that - I appreciate your help.

    As you say, at least it works currently.

    Kind regards,

    Darren 

     

    dbrook007
  • 05-28-2008 6:49 AM In reply to

    Re: Event Validation in ASP.Net 2.0 Ajax

    This happens if a user post the page (any action to post the page) before it loads completely. Put some code so that your users can not post the page( disable the buttons or something) before it loads fully.

Page 1 of 1 (10 items)