RadGrid Error with Edit ImageButton

4 posts, 0 answers
  1. Tom Gibson
    Tom Gibson avatar
    18 posts
    Member since:
    Aug 2007

    Posted 15 Aug 2008 Link to this post

    Hi,

    I'm having a problem with edit button in the RadGrid. Everything works fine when I use a ButtonType of linkButton, but when I switch the Button type to ImageButton, I get the following error.

    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.

    I don't understand why everything works fine with a linkbutton but not with an imagebutton. Does some different event get fired with an ImageButton?

    The aspx code is as follows:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="gridTest.aspx.cs" Inherits="<...our path here...>Presentation.Web.UI.InventoryManagement.gridTest" %> 
     
    <%@ Register Assembly="RadGrid.Net2" Namespace="Telerik.WebControls" TagPrefix="rad" %> 
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    <html xmlns="http://www.w3.org/1999/xhtml" > 
    <head runat="server">  
        <title>Untitled Page</title> 
    </head> 
    <body> 
        <form id="form1" runat="server">  
        <div> 
            <rad:RadGrid ID="RadGrid1" runat="server" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" 
                AutoGenerateColumns="False"   
    EnableAJAX="True" GridLines="None" Skin="Outlook2007">  
                <ClientSettings> 
                    <Selecting AllowRowSelect="True" /> 
                </ClientSettings> 
                <MasterTableView DataKeyNames="StaustOutcomeId" CommandItemDisplay="Bottom" EditMode="InPlace" > 
                    <Columns> 
                    <rad:GridButtonColumn CommandName="Edit" UniqueName="Edit" Text="Edit" ButtonType="ImageButton" 
                    HeaderText="Edit">  
                    </rad:GridButtonColumn> 
    <rad:GridBoundColumn DataField="Outcome" HeaderText="Outcome" SortExpression="Outcome" 
                            UniqueName="Outcome">  
                        </rad:GridBoundColumn> 
                        <rad:GridBoundColumn DataField="Status" HeaderText="Status" SortExpression="Status" 
                            UniqueName="Status">  
                        </rad:GridBoundColumn> 
                        <rad:GridBoundColumn DataField="Description" HeaderText="Description" SortExpression="Description" 
                            UniqueName="Description">  
                        </rad:GridBoundColumn> 
                        <rad:GridCheckBoxColumn DataField="IsActive" DataType="System.Boolean" HeaderText="IsActive" 
                            SortExpression="IsActive" UniqueName="IsActive">  
                        </rad:GridCheckBoxColumn> 
                        <rad:GridBoundColumn DataField="SalesChannel" HeaderText="SalesChannel" SortExpression="SalesChannel" 
                            UniqueName="SalesChannel">  
                        </rad:GridBoundColumn> 
                        <rad:GridBoundColumn DataField="StaustOutcomeId" DataType="System.Int32" HeaderText="StaustOutcomeId" 
                            ReadOnly="True" SortExpression="StaustOutcomeId" UniqueName="StaustOutcomeId">  
                        </rad:GridBoundColumn> 
                    </Columns> 
                    <ExpandCollapseColumn Resizable="False" Visible="False">  
                        <HeaderStyle Width="20px" /> 
                    </ExpandCollapseColumn> 
                    <RowIndicatorColumn Visible="False">  
                        <HeaderStyle Width="20px" /> 
                    </RowIndicatorColumn> 
                       
                </MasterTableView> 
            </rad:RadGrid> 
              
        </div> 
        </form> 
    </body> 
    </html> 
     


    And the code behind is
    using System;  
    using System.Data;  
    using System.Configuration;  
    using System.Collections;  
    using System.Web;  
    using System.Web.Security;  
    using System.Web.UI;  
    using System.Web.UI.WebControls;  
    using System.Web.UI.WebControls.WebParts;  
    using System.Web.UI.HtmlControls;  
    using System.Collections.Generic;  
     
    namespace <...our path here...>.Presentation.Web.UI.InventoryManagement  
    {  
        public partial class gridTest : System.Web.UI.Page  
        {  
            protected void Page_Load(object sender, EventArgs e)  
            {  
                List<StatusOtcm> lst = new List<StatusOtcm>(3);  
                for (int i=0; i<3; i++)  
                    lst.Add(new StatusOtcm());  
     
                RadGrid1.DataSource = lst;  
                RadGrid1.DataBind();  
            }  
        }  
     
        class StatusOtcm  
        {  
            public string Description  
            {  
                get { return "some Description"; }  
     
            }  
            public string Outcome  
            {  
                get { return "OC"; }  
     
            }  
     
            public string Status  
            {  
                get { return "Complete"; }  
     
            }  
            public bool IsActive  
            {  
                get { return true; }  
     
            }  
            public string SalesChannel  
            {  
                get { return "P"; }  
     
            }  
            public int StaustOutcomeId  
            {  
                get { return 25;}  
     
            }  
        }  
    }  
     


    Any ideas?

    Thanks,

    Tom

  2. Shinu
    Shinu avatar
    17723 posts
    Member since:
    Mar 2007

    Posted 17 Aug 2008 Link to this post

    Hi Tom,

    I found the following forum link which discusses a similar error. Go through the forum discussion and see if it helps.
    GridButtonColumn causing invalid postback.

    Shinu.

  3. Tom Gibson
    Tom Gibson avatar
    18 posts
    Member since:
    Aug 2007

    Posted 18 Aug 2008 Link to this post

    Unfortuantely, I still not able to get it working. It does seem strange that everything works fine for a link button,  but not for an image button.

  4. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1850 posts
    Member since:
    Sep 2012

    Posted 19 Aug 2008 Link to this post

    Hi Tom,

    The problem is caused by the DataBind call after setting DataSource. I'd suggest you move the data-binding logic into the NeedDataSource event as follows:

        protected void RadGrid1_NeedDataSource(object source, Telerik.WebControls.GridNeedDataSourceEventArgs e) 
        { 
            List<StatusOtcm> lst = new List<StatusOtcm>(3); 
            for (int i = 0; i < 3; i++) 
                lst.Add(new StatusOtcm()); 
     
            RadGrid1.DataSource = lst; 
        } 

    You can read more about the recommended "Advanced data-binding" technique in the documentation here.

    Best wishes,
    Konstantin Petkov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

Back to Top