Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Control inside asp:Repeater generates ArgumentException: Invalid postback or callback argument.

Reply
Thread Tools

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

 
 
Timbo
Guest
Posts: n/a
 
      05-05-2006
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

 
Reply With Quote
 
 
 
 
bruce barker \(sqlwork.com\)
Guest
Posts: n/a
 
      05-05-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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
>



 
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
GridView - Invalid postback or callback argument - ASP.NET 2.0 JULO ASP .Net 1 10-29-2008 05:18 PM
Invalid postback or callback argument problem kevin goff ASP .Net 2 08-04-2006 02:33 PM
Invalid postback or callback argument. Ray Stevens ASP .Net 2 03-28-2006 04:09 PM
"Invalid postback or callback argument" Amil ASP .Net 4 03-17-2006 07:04 AM
Got an error :Invalid postback or callback argument nitin.bajaj@rediffmail.com ASP .Net 0 11-16-2005 06:42 AM



Advertisments