ASP.NET AJAX Postback Event Validation

by JoeStagner 8/14/2007 3:17:19 PM

In my video “How Do I Use the Cascading Drop Down Control Extender”  I demonstrate setting EnableEventValidation=”false” at the page level and mention that you can leave the default (which is true) and individually authorize client event.

Since I’ve had a number of email about this, I thought I’d comment on the issue here.

It turns out that it’s actually a bit tricky in the case of using the Cascading Drop Down Control Extender when the Drop-Down values are dynamic. (Meaning they come from a data-source where items might be added after your code is written.)

The reason is that you need to SPECIFY what values are valid for the post-back.

Example, in the Render or Pre-Render methods you could:

   ClientScript.RegisterForEventValidation( _MyList.SomeUniqueID, “Red”);

   ClientScript.RegisterForEventValidation( _MyList.SomeUniqueID, “Green”); 

   ClientScript.RegisterForEventValidation( _MyList.SomeUniqueID, “Blue”);

The issue here is the “Red”, “Green” etc.

Of course, you could pull them from the database at runtime and call RegisterForEventValidation for each value.

Rather than write about all the details I’ll point you to a pair of excellent blog postings by K. Scott Allen over at OdeToCode.com

Read HERE: http://odetocode.com/Blogs/scott/archive/2006/03/20/3145.aspx

And HERE: http://odetocode.com/Blogs/scott/archive/2006/03/21/3153.aspx

Thanks Scott! Good stuff !

Currently rated 3.3 by 3 people

  • Currently 3.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Related posts

Comments

8/15/2007 9:12:24 AM

i agree

Jack Smith

9/25/2007 7:50:05 PM

Iam getting the below error message when i implement AJAX. I work in C#.


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.

Can you please help me

vara

10/10/2007 5:05:44 AM

Wonder if this is related. I have developed a problem using Cascading Drop down in C#. I have a cascade of 3 and another of 4 which progressively add dynamic content. The last ddl in the cascade does not hold state after it is selected? Any other refresh to the page also results in 'resetting' the last ddl to index 0. What is going on here?

John Rieder

1/3/2008 1:53:45 PM

Hi Joe,

That's a help, thank you!

If you know that the problem is with the dynamic values, why do you show us an example with hard-coded values? :/

If it is the cascadingDropdown that calls a webMethod, when should we use the registerForEventValidation?

On the cascadingDropDown on the OnPreRender event or on the dropDownList?

It would be great if you could extend the "how do I" video... You tell us that in a future video you will show us how, but I've seen them all, and haven't seen you doing it so far... Have i missed that in a video or it's you that hasn't posted it yet?

Hope to hear from you soon.

Kind Regards,
Chris

Chris

1/10/2008 8:05:08 PM

Thank you so much for this post! In my case the best solution was to create the DynamicDropDownList that was in the second link you posted (without any methods or attributes) thus disabling the Event Validation for only the one control on my page.

Jerry

Powered by BlogEngine.NET 1.3.0.0
Theme by Mads Kristensen

About your host.

Name of author Joe Stagner
?????

E-mail me Send mail

Calendar

<<  September 2008  >>
MoTuWeThFrSaSu
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

View posts in large calendar

Pages

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in