Sample usage of ClientScriptManager.RegisterForEventValidation

  • Thread starter Thread starter n33470
  • Start date Start date
N

n33470

Hi all,

I have a dropDownList on a web page that is populated by client-side
script. I get an error on PostBack of the page. I've seen quite a few
posts about this, so I understand the issue, and why it's occurring. I
know that I need to remove the automatic event validation that ASP.NET
is performing on the control. One of my options is to use the page
directive enableEventValidation="false". I'd rather not do this for
the entire page, I'd rather remove the event validation for only the
dropdownlist.

I've read that ClientScriptManager.RegisterForEventValidation can be
used for this. However, I haven't been able to figure out exactly how
to use it. I have overloaded the Render() method like this (the
object cboLookup is the DropDownList):

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


this.Page.ClientScript.RegisterForEventValidation(cboLookup.ID);

}

However, after doing this I still have the problem when the page is
posted back. I think I'm missing an extra step here, but I can't
figure out what it is. The method name is called
"RegisterForEventValidation", however I actually want to un-register
the control from ASP.NET event validation. How do you do this?

Can someone provide a simple example of how to bypass the automatic
event validation code on postback of the page for a single control.

--steve
 
I added EnableEventValidation="false" to my @Page directive, and now i can
submit the form with the client-side populated listbox. In my Protected Sub
btnSave_Click event, when I iterate the listbox that was populated
client-side, I cannot see any items in the list. Any ideas?
 
www,

Here is the same post on a different forum with a few more comments:
http://forums.asp.net/1139510/ShowPost.aspx

With respect to your comment about reading the DDL on postback in your
click handler. The viewstate of the DDL contains the contents of the
DDL when the page was originally rendered. Thus, on post back the
viewstate get applied to the DDL, and when you iterate the list it has
the original contents restored, which doesn't do any good if the list
is client-populated. On postback, the only thing from the DDL that
you can access is the selected item, and that can be found in the
Response.Form variables.

HTH,

--steve
 

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

Back
Top