Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Grid > RadGrid Error with Edit ImageButton

Not answered RadGrid Error with Edit ImageButton

Feed from this thread
  • Tom Gibson avatar

    Posted on Aug 15, 2008 (permalink)

    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

    Reply

  • Posted on Aug 17, 2008 (permalink)

    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.

    Reply

  • Say Hello to Telerik's PivotGrid for ASP.NET AJAX, Silverlight, WPF and WinForms. Now packed with OLAP support.
  • Tom Gibson avatar

    Posted on Aug 18, 2008 (permalink)

    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.

    Reply

  • Konstantin Petkov Konstantin Petkov admin's avatar

    Posted on Aug 19, 2008 (permalink)

    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.

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Grid > RadGrid Error with Edit ImageButton
Related resources for "RadGrid Error with Edit ImageButton"

ASP.NET Grid Features  |  Documentation  |  Demos  |  Step-by-step Tutorial  ]