Hi, I had the same issue, where I had a datalist with an Image Button. I was using the ItemCreated/ItemDataBound to set the ImageUrl of the image. I also did not have my databinding code in a if(!Page.IsPostBack). Once I changed my asp.net html code to
be <asp:ImageButton ID="btn" runat="server" ImageUrl='<%# Container.DataItem %>'> It worked fine. I think you have to be careful how your datagrid is bound.
I had an experience with DataGrid. One of it's columns was "Select" button. When I was clicking "Select" button of any row I had received this error message: "Invalid postback or callback argument. Event validation is enabled using in configuration or 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 changed several codes, finally I succeeded. my experience route:
1: I changed page attribute to EnableEventValidation="false". But it didn't work.
( not only is this dangerous for security reason, my event handler wasn't called:" void Grid_SelectedIndexChanged(object sender, EventArgs e)")
2: I implemented ClientScript.RegisterForEventValidation in Render method. But it didn't work.
protected override void Render(HtmlTextWriter writer) { foreach (DataGridItem item in this.Grid.Items) { Page.ClientScript.RegisterForEventValidation(item.UniqueID); foreach (TableCell cell in (item as TableRow).Cells) { Page.ClientScript.RegisterForEventValidation(cell.UniqueID);
foreach (System.Web.UI.Control control in cell.Controls) { if (control is Button) Page.ClientScript.RegisterForEventValidation(control.UniqueID); } } } }
3: I changed my button type in grid column from "PushButton" to "LinkButton".
It worked!
("<asp:ButtonColumn ButtonType="LinkButton" CommandName="Select"></asp:ButtonColumn>") I think if you can change your button to other controls like "LinkButton" in other cases, it would work properly.
First Google result so i'll add one for "if(!Page.IsPostBack)" in codebehind. I had a repeater with a databound imagebutton. When the button is clicked it threw that error. I finally realized that was trying to rebind my datasource on every postback. It's amazing
what staring at your code for 15 minutes can do.
Not sure if this helps but I just made a break through with this error after quite literally trawling the web for answers.
On my page I had 3 gridviews displaying different information, on one grid I wanted a link to post another page using postbackurl which carried the form values across.
It turned out that turning off the view state on the other grids allowed the postback to function.
mangokun
Member
6 Points
3 Posts
Re: Invalid postback or callback argument
Jun 07, 2008 07:03 AM|LINK
http://aspnet.4guysfromrolla.com/demos/printPage.aspx?path=/articles/122006-1.aspx
</div>Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
'###this removes the no forms error by overriding the error
End Sub
Public Overrides Property EnableEventValidation() As Boolean
Get
Return False
End Get
Set(ByVal value As Boolean)
'DO NOTHING
End Set
End Property
http://www.geocities.com/mangokun/
Bring on the black and white
http://www.imdb.com/title/tt0388556/
jbarber2008
Member
2 Points
1 Post
Re: Invalid postback or callback argument
Oct 21, 2008 10:11 PM|LINK
Hi, I had the same issue, where I had a datalist with an Image Button. I was using the ItemCreated/ItemDataBound to set the ImageUrl of the image. I also did not have my databinding code in a if(!Page.IsPostBack). Once I changed my asp.net html code to be <asp:ImageButton ID="btn" runat="server" ImageUrl='<%# Container.DataItem %>'> It worked fine. I think you have to be careful how your datagrid is bound.AmirPalang
Member
2 Points
1 Post
Re: Invalid postback or callback argument
Nov 09, 2008 07:19 AM|LINK
I had an experience with DataGrid. One of it's columns was "Select" button. When I was clicking "Select" button of any row I had received this error message: "Invalid postback or callback argument. Event validation is enabled using in configuration or 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 changed several codes, finally I succeeded. my experience route:
1: I changed page attribute to EnableEventValidation="false". But it didn't work.
( not only is this dangerous for security reason, my event handler wasn't called:" void Grid_SelectedIndexChanged(object sender, EventArgs e)")
2: I implemented ClientScript.RegisterForEventValidation in Render method. But it didn't work.
protected override void Render(HtmlTextWriter writer) { foreach (DataGridItem item in this.Grid.Items) { Page.ClientScript.RegisterForEventValidation(item.UniqueID); foreach (TableCell cell in (item as TableRow).Cells) { Page.ClientScript.RegisterForEventValidation(cell.UniqueID); foreach (System.Web.UI.Control control in cell.Controls) { if (control is Button) Page.ClientScript.RegisterForEventValidation(control.UniqueID); } } } }
3: I changed my button type in grid column from "PushButton" to "LinkButton". It worked!
("<asp:ButtonColumn ButtonType="LinkButton" CommandName="Select"></asp:ButtonColumn>") I think if you can change your button to other controls like "LinkButton" in other cases, it would work properly.
chtvn
Member
8 Points
4 Posts
Re: Invalid postback or callback argument
Dec 06, 2008 08:43 PM|LINK
oh the solution for this is that "Bind data in the (!isPostBack)" (cannot believe but it does work :-( )
should write smt like
if (!IsPostBack) { this.listData.DataSource = list; this.listData.DataBind(); }savindra.ban...
Member
22 Points
13 Posts
Re: Invalid postback or callback argument
Jan 08, 2009 11:41 AM|LINK
set EnableEventValidation="false" in the page directive
<%@ Page Language="C#" EnableEventValidation="false" %>
Reason Man
Member
2 Points
1 Post
Re: Invalid postback or callback argument
Jan 09, 2009 07:42 AM|LINK
bobster9999
Member
6 Points
3 Posts
Re: Invalid postback or callback argument
Jan 15, 2009 10:10 PM|LINK
Not sure if this helps but I just made a break through with this error after quite literally trawling the web for answers.
On my page I had 3 gridviews displaying different information, on one grid I wanted a link to post another page using postbackurl which carried the form values across.
It turned out that turning off the view state on the other grids allowed the postback to function.
Hope this helps anyone.
IIS7 / .NET 2 / VS2008