Note that there are some explanatory texts on larger screens.

plurals
  1. POInvalid postback or callback argument error when button click - Beginner
    primarykey
    data
    text
    <p>I am getting the following error;</p> <blockquote> <p>Invalid postback or callback argument. Event validation is enabled using in configuration or &lt;%@ 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.</p> </blockquote> <p>I added a columm, and added a button into it, When the button is fired the following C# code gets executed;</p> <p>ASP.NET Code</p> <pre><code> &lt;Columns&gt; &lt;%-- &lt;asp:BoundField /&gt; Definitions here --%&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:Button ID="AddButton" runat="server" CommandName="AddToCart" CommandArgument="&lt;%# ((GridViewRow) Container).RowIndex %&gt;" Text="Add to Cart" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; </code></pre> <p>C#</p> <pre><code> protected void GridView1_RowCommand(object sender,GridViewCommandEventArgs e) { if (e.CommandName == "AddToCart") { int index = Convert.ToInt32(e.CommandArgument); // Retrieve the row that contains the button // from the Rows collection. GridViewRow row = GridView1.Rows[index]; } } </code></pre> <p>How do i get rid of this error;</p> <p>I added <code>&lt;globalization requestEncoding="utf-8"/&gt;</code> but the error is still there. `</p> <p><strong>UPDATE</strong></p> <pre><code> &lt;asp:GridView runat="server" ID="gdv" AutoGenerateColumns="True" OnSorting="sortRecord" AllowSorting="true" DataKeyNames="HotelName" CellPadding="4" Width="746px"&gt; &lt;Columns&gt; &lt;%-- &lt;asp:BoundField /&gt; Definitions here --%&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:Button ID="AddButton" runat="server" CommandName="AddToCart" CommandArgument="&lt;%# ((GridViewRow) Container).RowIndex %&gt;" Text="Add to Cart" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload