Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeUsing DNN Platf...Using DNN Platf...Using Modules a...Using Modules a...A critical error has occurred. Invalid postback or callback argumentA critical error has occurred. Invalid postback or callback argument
Previous
 
Next
New Post
10/1/2012 4:43 PM
 

Hi,

I have gridview in my module and applying edit and delete functionality manually instead of using datasource. But when i click on the edit button in gridview its give me this error. when i turn of enableEventValidation in config file false or add EnableEventValidation in page its gave me an other error. what i have to rid off this error.

A critical error has occurred. 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.

Here is my ascx code

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Location.ascx.cs" Inherits="KontorBokning.Location"%>

<asp:Button ID="btnCreate" runat="server" Text="Create" 
    onclick="btnCreate_Click" /><br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    DataKeyNames="ID" onrowupdating="GridView1_RowUpdating" 
    onrowediting="GridView1_RowEditing">
    <Columns>
        <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
            ReadOnly="True" SortExpression="ID" Visible="False" />
        <asp:BoundField DataField="Location" HeaderText="Location" 
            SortExpression="Location" />
        <asp:BoundField DataField="CreateDate" HeaderText="CreateDate" 
            SortExpression="CreateDate" Visible="False" />
        <asp:BoundField DataField="UpdateDate" HeaderText="UpdateDate" 
            SortExpression="UpdateDate" Visible="False" />
        <asp:BoundField DataField="SystemUser" HeaderText="SystemUser" 
            SortExpression="SystemUser" Visible="False" />
        <asp:TemplateField HeaderText="Editera" ShowHeader="False">
            <EditItemTemplate>
                <asp:ImageButton ID="btnUpdate" runat="server" CausesValidation="True" 
                    CommandName="Update" ImageUrl="Images/save.png" Text="Update" />
                &nbsp;<asp:ImageButton ID="btnCancel" runat="server" CausesValidation="False" 
                    CommandName="Cancel" ImageUrl="Images/cancel.png" Text="Cancel" />
            </EditItemTemplate>
            <ItemTemplate>
                <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" 
                    CommandName="Edit" ImageUrl="Images/update.png" Text="Edit"  />
            </ItemTemplate>
            <ItemStyle HorizontalAlign="Center" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Ta bort" ShowHeader="False">
            <ItemTemplate>
                <asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" 
                    CommandName="Delete" ImageUrl="Images/delete.png" Text="Delete" />
            </ItemTemplate>
            <ItemStyle HorizontalAlign="Center" />
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Here is my code behind file code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetNuke;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using System.Data;
using System.Data.OleDb;

namespace KontorBokning
{
    public partial class Location : PortalModuleBase, IActionable
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadLocations();
        }

        #region "Optional Interfaces"

        /// ----------------------------------------------------------------------------- 
        /// <summary> 
        /// Registers the module actions required for interfacing with the portal framework 
        /// </summary> 
        /// <value></value> 
        /// <returns></returns> 
        /// <remarks></remarks> 
        /// <history> 
        /// </history> 
        /// ----------------------------------------------------------------------------- 
        public ModuleActionCollection ModuleActions
        {
            get
            {
                ModuleActionCollection Actions = new ModuleActionCollection();
                Actions.Add(GetNextActionID(), Localization.GetString(ModuleActionType.AddContent, this.LocalResourceFile),
                   ModuleActionType.AddContent, "", "add.gif", EditUrl(), false, DotNetNuke.Security.SecurityAccessLevel.Edit,
                    true, false);
                return Actions;
            }
        }

        #endregion
        public void LoadLocations() {
            Connection Conn = new Connection();
            Conn.OledbConntion();
            Conn.OpenOledbConnection();

            string Qry = "SELECT * FROM [KontorLocation]";
            System.Data.OleDb.OleDbCommand cmd = new OleDbCommand(Qry, Conn.oledbconn);
            System.Data.OleDb.OleDbDataAdapter da = new OleDbDataAdapter(cmd);
            System.Data.DataTable dt = new DataTable("Location");
            da.Fill(dt);

            GridView1.DataSource = dt;
            GridView1.DataBind();

            Conn.CloseOledbConnection();
        }
        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            
                Connection Conn = new Connection();
                Conn.OledbConntion();
                Conn.OpenOledbConnection();
                string Qry="", Location="";
                if (this.ViewState["Control"] == "Insert") {
                    Qry = "Insert Into [KontorLocation] ([Location],[CreateDate],[UpdateDate],[SystemUser]) ";
                    Qry += "Values('" +Location+"', '"+ DateTime.Now.ToShortDateString() +"', '"+ DateTime.Now.ToShortDateString()+"', '"+ UserInfo.Username.ToString() +"'";
                    System.Data.OleDb.OleDbCommand cmd = new OleDbCommand(Qry, Conn.oledbconn);
                    System.Data.OleDb.OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                    System.Data.DataTable dt = new DataTable("New Location");
                    da.Fill(dt);
                    this.ViewState["Control"] = "Update";

                }
                else {
                    Qry = "Update [KontorLocation] Set [Location] = '" + Location + "', [UpdateDate] = '" + DateTime.Now.ToShortDateString() + "', [SystemUser] = '" + UserInfo.Username.ToString() + "' Where ID= " + GridView1.DataKeys[Convert.ToInt32(e.RowIndex)]["ID"].ToString() + "";
                    System.Data.OleDb.OleDbCommand cmd = new OleDbCommand(Qry, Conn.oledbconn);
                    System.Data.OleDb.OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                    System.Data.DataTable dt = new DataTable("Update Location");
                    da.Fill(dt);
                }
                

                Conn.CloseOledbConnection();
        }

        protected void btnCreate_Click(object sender, EventArgs e)
        {
            Connection Conn = new Connection();
            Conn.OledbConntion();
            Conn.OpenOledbConnection();

            string Qry = "SELECT * FROM [KontorLocation]";
            System.Data.OleDb.OleDbCommand cmd = new OleDbCommand(Qry,Conn.oledbconn);
            System.Data.OleDb.OleDbDataAdapter da = new OleDbDataAdapter(cmd);
            System.Data.DataTable dt = new DataTable("Location");
            da.Fill(dt);

            DataRow Row = dt.NewRow();
            dt.Rows.InsertAt(Row, 0);
            GridView1.EditIndex = 0;
            GridView1.DataSource = dt;
            GridView1.DataBind();
            this.ViewState["Control"] = "Insert";
            Conn.CloseOledbConnection();
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
            LoadLocations();
        }

       
    }
}




 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Using Modules a...Using Modules a...A critical error has occurred. Invalid postback or callback argumentA critical error has occurred. Invalid postback or callback argument


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out