By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,590 Members | 1,140 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,590 IT Pros & Developers. It's quick & easy.

Control inside asp:Repeater generates ArgumentException: Invalid postback or callback argument.

P: n/a
Hi all,

This is my first message here so i'll try and include all the
information that will help you help me out, if possible.

Basically I am using C# in ASP.NET 2.0 and have a Repeater control in
my aspx page with two image buttons, one for an edit command, another a
delete command. Here is a cut down code fragment.

---------------------------------------------------------------------------------------------------------------------------

<asp:Repeater ID="rptData" runat="server">
<ItemTemplate>
<div class="row">
<p class="dataPara">
<span style="float: right; padding-left: 5px;">
<asp:ImageButton ID="imgbDelete" runat="server"
ImageUrl="img/delete.gif" AlternateText="Delete" CommandName="Delete"
/>
</span>
<span style="float: right; padding-left: 5px;">
<asp:ImageButton ID="imgbEdit" runat="server"
ImageUrl="img/edit.gif" AlternateText="Edit" CommandName="Edit" />
</span>
<%# DataBinder.Eval(Container.DataItem, "Item") %>
</p>
</div>
</ItemTemplate>
</asp:Repeater>

---------------------------------------------------------------------------------------------------------------------------

Basically what happens is that i get a set of rows with delete and edit
buttons for each record in my dataset, which is as expected, however as
soon as you click one of these buttons i recieve the following error.

In case you wondered why i'm not using a DataGrid, the reason is
because the HTML for the item template is alot more complex, this is
simply cut down to illustrate my problem i'm getting.

---------------------------------------------------------------------------------------------------------------------------

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.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

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.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[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.]
System.Web.UI.ClientScriptManager.ValidateEvent(St ring uniqueId,
String argument) +2080220
System.Web.UI.Control.ValidateEvent(String uniqueID, String
eventArgument) +106
System.Web.UI.WebControls.ImageButton.RaisePostBac kEvent(String
eventArgument) +32

System.Web.UI.WebControls.ImageButton.System.Web.U I.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
+33
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+5102

---------------------------------------------------------------------------------------------------------------------------

Obviously setting the pages requireseventvalidation="false" in
web.config removes this error, but i would rather find a work around to
this. After searching the web my first attempts at doing this have been
unsuccessful, and i'm now at a dead end. So far i have tried the
following code in my code behind.

---------------------------------------------------------------------------------------------------------------------------

protected override void Render(HtmlTextWriter writer)
{
for (int i = 0; i < tblData.Rows.Count; i++)
{
Page.ClientScript.RegisterForEventValidation("rptD ata$ctl"
+ String.Format("{0:00}", i) + "$imgbEdit");
Page.ClientScript.RegisterForEventValidation("rptD ata$ctl"
+ String.Format("{0:00}", i) + "$imgbDelete");
RegisterRequiresPostBack(rptData.Items[i].Controls[1]);
RegisterRequiresPostBack(rptData.Items[i].Controls[3]);
}
base.Render(writer);
}

---------------------------------------------------------------------------------------------------------------------------

I obtained the unique ID's for the controls by iterating through the
controls in each row of the repeater to find them and then used the
following code above to try and register them. However this does not
seem to solve the problem so i think i'm not obtaining the right ID's
for the controls or i'm missing something else or not understanding the
requirements of the function. In case anyone is wondering the
RegisterRequiresPostBack() function was added after i read a suggestion
to add it from another thread referencing the same exception, but this
does not seem to solve the problem either.

Any help would be greatful, otherwise i'll have to resort to turning
off event validation which ideally i don't want to do.

Kind Regards,

Tim Anderson

May 5 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
most likely you are not recreating the repeater the same on the postback, so
the control ids on the postback page don't match the original rendered page.

-- bruce (sqlwork.com)
"Timbo" <ti**************@btconnect.com> wrote in message
news:11*********************@j73g2000cwa.googlegro ups.com...
Hi all,

This is my first message here so i'll try and include all the
information that will help you help me out, if possible.

Basically I am using C# in ASP.NET 2.0 and have a Repeater control in
my aspx page with two image buttons, one for an edit command, another a
delete command. Here is a cut down code fragment.

---------------------------------------------------------------------------------------------------------------------------

<asp:Repeater ID="rptData" runat="server">
<ItemTemplate>
<div class="row">
<p class="dataPara">
<span style="float: right; padding-left: 5px;">
<asp:ImageButton ID="imgbDelete" runat="server"
ImageUrl="img/delete.gif" AlternateText="Delete" CommandName="Delete"
/>
</span>
<span style="float: right; padding-left: 5px;">
<asp:ImageButton ID="imgbEdit" runat="server"
ImageUrl="img/edit.gif" AlternateText="Edit" CommandName="Edit" />
</span>
<%# DataBinder.Eval(Container.DataItem, "Item") %>
</p>
</div>
</ItemTemplate>
</asp:Repeater>

---------------------------------------------------------------------------------------------------------------------------

Basically what happens is that i get a set of rows with delete and edit
buttons for each record in my dataset, which is as expected, however as
soon as you click one of these buttons i recieve the following error.

In case you wondered why i'm not using a DataGrid, the reason is
because the HTML for the item template is alot more complex, this is
simply cut down to illustrate my problem i'm getting.

---------------------------------------------------------------------------------------------------------------------------

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.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

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.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[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.]
System.Web.UI.ClientScriptManager.ValidateEvent(St ring uniqueId,
String argument) +2080220
System.Web.UI.Control.ValidateEvent(String uniqueID, String
eventArgument) +106
System.Web.UI.WebControls.ImageButton.RaisePostBac kEvent(String
eventArgument) +32

System.Web.UI.WebControls.ImageButton.System.Web.U I.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
+33
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+5102

---------------------------------------------------------------------------------------------------------------------------

Obviously setting the pages requireseventvalidation="false" in
web.config removes this error, but i would rather find a work around to
this. After searching the web my first attempts at doing this have been
unsuccessful, and i'm now at a dead end. So far i have tried the
following code in my code behind.

---------------------------------------------------------------------------------------------------------------------------

protected override void Render(HtmlTextWriter writer)
{
for (int i = 0; i < tblData.Rows.Count; i++)
{
Page.ClientScript.RegisterForEventValidation("rptD ata$ctl"
+ String.Format("{0:00}", i) + "$imgbEdit");
Page.ClientScript.RegisterForEventValidation("rptD ata$ctl"
+ String.Format("{0:00}", i) + "$imgbDelete");
RegisterRequiresPostBack(rptData.Items[i].Controls[1]);
RegisterRequiresPostBack(rptData.Items[i].Controls[3]);
}
base.Render(writer);
}

---------------------------------------------------------------------------------------------------------------------------

I obtained the unique ID's for the controls by iterating through the
controls in each row of the repeater to find them and then used the
following code above to try and register them. However this does not
seem to solve the problem so i think i'm not obtaining the right ID's
for the controls or i'm missing something else or not understanding the
requirements of the function. In case anyone is wondering the
RegisterRequiresPostBack() function was added after i read a suggestion
to add it from another thread referencing the same exception, but this
does not seem to solve the problem either.

Any help would be greatful, otherwise i'll have to resort to turning
off event validation which ideally i don't want to do.

Kind Regards,

Tim Anderson

May 5 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.