Error on post back

W

Wayne Sepega

I have two drop downs on my web form. The contents of DropDown2 depends on
what is currently selected in DropDown1. I use client side java script to
re-populate DropDown2 whenever DropDown1 changes.

In doing so, if I select a value in DropDown2 that wasn't there when the
page was built I receive the following error:

Exception Details: System.ArgumentException: 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 have tried doing the following:

protected override void Render(HtmlTextWriter writer)
{
DateTime curDate;
int dateCount = br.MaxPickUpDateDays + br.MaxExpirationDays;

if (subscription.ExpirationDate <= DateTime.Now.Date)
ClientScript.RegisterForEventValidation("DropDown2",
subscription.ExpirationDate.ToString(DateFormat));

for (int i = 0; i < dateCount; i++)
{
curDate = System.DateTime.Now.AddDays(i).Date;
ClientScript.RegisterForEventValidation("DropDown2",
curDate.ToString(DateFormat));
}
base.Render(writer);
}


However, when I do the above my DropDown2.SelectedValue always comes back
blank.

I've spent about an hr or so working on this and searching google, but all
the examples I find give me back a blank selected value. A point in the
right direction or some suggestions would be appreciated.

Thanks
Wayne Sepega
 
H

Henrique Mello

if the problem is with the validation, have you tryed to set it to off?
enableEventValidation="false"
 
W

Wayne Sepega

No, but given that it's set to true for security reasons and I would like to
make use of the feature it provides, I did not want to set it to false.

I would rather know why the ClientScript.RegisterForEventValidation is not
working like I understand it should.

Thanks
Wayne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top