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

T

Timbo

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(String uniqueId,
String argument) +2080220
System.Web.UI.Control.ValidateEvent(String uniqueID, String
eventArgument) +106
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String
eventArgument) +32

System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection 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("rptData$ctl"
+ String.Format("{0:00}", i) + "$imgbEdit");
Page.ClientScript.RegisterForEventValidation("rptData$ctl"
+ String.Format("{0:00}", i) + "$imgbDelete");
RegisterRequiresPostBack(rptData.Items.Controls[1]);
RegisterRequiresPostBack(rptData.Items.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
 
B

bruce barker \(sqlwork.com\)

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 said:
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(String uniqueId,
String argument) +2080220
System.Web.UI.Control.ValidateEvent(String uniqueID, String
eventArgument) +106
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String
eventArgument) +32

System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection 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("rptData$ctl"
+ String.Format("{0:00}", i) + "$imgbEdit");
Page.ClientScript.RegisterForEventValidation("rptData$ctl"
+ String.Format("{0:00}", i) + "$imgbDelete");
RegisterRequiresPostBack(rptData.Items.Controls[1]);
RegisterRequiresPostBack(rptData.Items.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
 

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

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top