473,387 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Sample usage of ClientScriptManager.RegisterForEventValidation

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

Dec 9 '05 #1
3 21637
I have the same problem. Have you found a solution?

"n33470" wrote:
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

Jan 3 '06 #2
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?

"n33470" wrote:
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

Jan 3 '06 #3
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
www051906 wrote:
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?

"n33470" wrote:
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


Jan 3 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: stewart | last post by:
Hi. I have an asp:dropdown control to which I add items on the client, when the page is posted back I get this error message. Invalid postback or callback argument. Event validation is enabled...
0
by: Lloyd Dupont | last post by:
At some stage I'm inherithing from a kind of 'web component' which don't inherit from SWU.Control and have no ClientScript property. However I need to know (in order to make it work) an URL which...
7
by: Varangian | last post by:
Hi all, I have a question, what does the function ClientScriptManager.RegisterForEventValidation really does? Does it means securing your client side code? more security? The question is how...
1
by: chris | last post by:
This topic is to get some details about the Event Validation feature in ASP.NET 2.0. I have researched this topic quite a bit via the web, and understand, for the most part how this works and why...
2
by: Albert | last post by:
I’ve been getting this error after converting my app from .NET 1.1 to .Net 2.0. RegisterForEventValidation can only be called during Render() An error occurs when I call ...
3
by: wind | last post by:
i use the code in exporting gridview to excel and and work just fine but when i adjust it to my implementation of a search record I'm getting the said error (registerforeventvalidation can only be...
2
by: DNB | last post by:
What is the difference between ClientScriptManager.RegisterClientScriptBlock and ClientScriptManager.RegisterClientScript Thanks DNB
1
by: news.rz.uni-karlsruhe.de | last post by:
What exactly is the difference between ScriptManager and ClientScriptManager? Do I use the ScriptManager whenever I use a script on an asp-ajax enabled page and the ClientScriptmanager...
7
by: AAaron123 | last post by:
I read the help on which says: The ClientScriptManager class is used to manage client-side scripts and add them to Web applications... But could use a little help. Can someone tell me what...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.