Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Sample usage of ClientScriptManager.RegisterForEventValidation

Reply
Thread Tools

Sample usage of ClientScriptManager.RegisterForEventValidation

 
 
n33470
Guest
Posts: n/a
 
      12-09-2005
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?d3d3MDUxOTA2?=
Guest
Posts: n/a
 
      01-03-2006
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
>
>

 
Reply With Quote
 
 
 
 
=?Utf-8?B?d3d3MDUxOTA2?=
Guest
Posts: n/a
 
      01-03-2006
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
>
>

 
Reply With Quote
 
n33470
Guest
Posts: n/a
 
      01-03-2006
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
> >
> >


 
Reply With Quote
 
notmyself(gal 2:20) notmyself(gal 2:20) is offline
Junior Member
Join Date: Oct 2006
Posts: 1
 
      10-06-2006
You should be able to override your render method like this:

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
If findGrid.Rows.Count > 0 Then
For Each row As GridViewRow In findGrid.Rows
If row.RowType = DataControlRowType.DataRow Then
row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(findGr id, "Select$" & row.RowIndex, True))
End If
Next
End If

MyBase.Render(writer)
End Sub


It has worked for me.
 
Reply With Quote
 
kevonh kevonh is offline
Junior Member
Join Date: Nov 2006
Posts: 1
 
      11-16-2006
Quote:
Originally Posted by notmyself(gal 2:20)
You should be able to override your render method like this:

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
If findGrid.Rows.Count > 0 Then
For Each row As GridViewRow In findGrid.Rows
If row.RowType = DataControlRowType.DataRow Then
row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(findGr id, "Select$" & row.RowIndex, True))
End If
Next
End If

MyBase.Render(writer)
End Sub


It has worked for me.
This worked BEAUTIFULLY!!!!!
 
Reply With Quote
 
rocky20 rocky20 is offline
Junior Member
Join Date: Nov 2007
Posts: 1
 
      11-28-2007
I have the sam problem my dropdownlist does'nt get populated with data from client side
Can you wrote this for dropdownlist cause this is for datagrid
where must i put this function in asp page?

Quote:
Originally Posted by notmyself(gal 2:20)
You should be able to override your render method like this:

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
If findGrid.Rows.Count > 0 Then
For Each row As GridViewRow In findGrid.Rows
If row.RowType = DataControlRowType.DataRow Then
row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(findGr id, "Select$" & row.RowIndex, True))
End If
Next
End If

MyBase.Render(writer)
End Sub


It has worked for me.
 
Reply With Quote
 
kennedyz kennedyz is offline
Junior Member
Join Date: Feb 2009
Posts: 1
 
      02-06-2009
In order to get around this problem, I simply had to add CausesValidation="True" to my <aspropDownList> control definition.
 
Reply With Quote
 
DougLynn DougLynn is offline
Junior Member
Join Date: Feb 2010
Posts: 1
 
      02-04-2010
One solution is to include all possible dropdownlist options, that are loaded by the javascript at sometime, in the initial (default) load for the page. I do this and then edit the values dynamically at the end of the page load using Page.ClientScript.RegisterStartupScript
 
Reply With Quote
 
AbercrombieLV AbercrombieLV is offline
Junior Member
Join Date: May 2010
Posts: 1
 
      05-30-2010
This is a really cool function (Page.ClientScript.GetPostBackEventReference)if works as advertised. I've targeted both the row and the button in the row that generate the error. I checked the page that was generated and it added the dopostback argument to the control just like I wanted (nice). But................ the error still comes up!!!! What am I missing? Here's the code I wrote. it's for ASP.Net 3.5 This thread goes back awhile so I don't know if something things have changed since 2.0......

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
For Each oGrv As GridViewRow In gvOrg.Rows
oBtn(0) = oGrv.FindControl("btnDelete")
If Not oBtn(0) Is Nothing Then
Page.ClientScript.RegisterForEventValidation(oBtn( 0).UniqueID, "")
oGrv.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(gvOrg, "Select$" & oGrv.RowIndex, True))
oBtn(0).Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(gvOrg, oBtn(0).UniqueID, True))
End If
Next
MyBase.Render(writer)
End Sub
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
retrieving CPU Usage and Memory Usage information in JAVA hvt Java 0 03-13-2007 01:09 PM
retrieving CPU Usage and Memory Usage information in JAVA hvt Java 0 03-13-2007 01:07 PM
looking for asp.net sample with vb.net backend sample is there one? Jake ASP .Net 0 02-09-2006 10:44 PM
Webchecker Usage - a problem with local usage Colin J. Williams Python 1 02-26-2004 12:28 AM
Need help on memory usage VS PF usage metfan Java 2 10-21-2003 01:58 PM



Advertisments