Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 11th, 2011, 10:35 AM
Authorized User
 
Join Date: Dec 2010
Posts: 21
Thanks: 4
Thanked 1 Time in 1 Post
Default Invalid postback when i try a delete command

I am attempting to add a delete command to my data grid, and it worked fine on my previous program, but now for some reason is giving me this error message:

Quote:
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.
The data grid is in this format:
HTML Code:
<asp:DataGrid id=dg runat="server"  ondeletecommand="Delete_Item">  
<columns>
<asp:buttoncolumn buttontype="PushButton"   
commandname="Delete" text="Remove All" />  
</columns>  
</asp:DataGrid>
and the "Delete_Item" subroutine is here:
Code:
Sub Delete_Item(s As Object, e As DataGridCommandEventArgs)  
 
    objDT = Session("Cart")  
    objDT.Rows(e.Item.ItemIndex).Delete()  
    Session("Cart") = objDT  
 
    dg.DataSource = objDT  
    dg.DataBind()
 
End Sub
So this used to remove a row from my data grid, but not anymore.

It would be super if someone could tell me what the problem is.
 
Old March 14th, 2011, 06:03 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

It would seem that you are binding the grid elsewhere in your code. Check to make sure you don't have binding code somewhere else, such as the Page_Load event.
 
Old March 15th, 2011, 10:57 AM
Authorized User
 
Join Date: Dec 2010
Posts: 21
Thanks: 4
Thanked 1 Time in 1 Post
Default

I have it call these functions on the page_load:

Code:
Private Sub Page_Load(s As Object, e As EventArgs)
	If Not IsPostBack Then
		makeCart()
	End If
		DataForGrid()
makeCart() looks like this:
Code:
Dim objDT As System.Data.DataTable 
Dim objDR As System.Data.DataRow   '<--These two lines apply for the whole script

Function makeCart()
if Session("Cart") is Nothing Then
objDT = New System.Data.DataTable("Cart") 
objDT.Columns.Add("ID", GetType(Integer)) 
objDT.Columns("ID").AutoIncrement = True 
objDT.Columns("ID").AutoIncrementSeed = 1 

objDT.Columns.Add("Quantity", GetType(Integer)) 
objDT.Columns.Add("Product", GetType(String)) 
objDT.Columns.Add("Item Cost", GetType(Decimal))
objDT.Columns.Add("Item Total", GetType(Decimal))

Session("Cart") = objDT 
End if
End Function
and DataforGrid() is in this wise:

Code:
Function DataforGrid()

	Dim objDT As System.Data.DataTable = CType(Session.Item("Cart"), System.Data.DataTable)

     dg.DataSource = objDT
     dg.DataBind()

End Function
But I can't just remove these. I need this in order to save the table when you navigate away from the data grid page. Is there some way I can have a "delete" command and still save the data grid?
 
Old March 16th, 2011, 10:06 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

put the DtaforGrid() call in the IF not page.ispostback code
The Following User Says Thank You to jbenson001 For This Useful Post:
MtheK (March 17th, 2011)
 
Old March 17th, 2011, 11:12 AM
Authorized User
 
Join Date: Dec 2010
Posts: 21
Thanks: 4
Thanked 1 Time in 1 Post
Thumbs up

Thanks! That worked great!

Code:
Private Sub Page_Load(s As Object, e As EventArgs)
	If Not IsPostBack Then
		DataForGrid()
		makeCart()
	End If
    
End Sub
I should be able to figure these things out, i guess, but anyways, thanks again for the help.
 
Old March 17th, 2011, 01:40 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I'm glad I was able to help. In most cases, you will only want to load the data for your controls if it is NOT a post back.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Error: Invalid postback or call back argument kalyanykk ASP.NET 2.0 Basics 0 August 26th, 2008 06:03 AM
Invalid postback or callback argument mallikalapati ASP.NET 2.0 Professional 4 February 20th, 2008 08:38 AM
Invalid UPDATE command Mr. Vage SQL Language 4 April 14th, 2007 05:59 PM
Invalid postback or callback argument everest ASP.NET 2.0 Professional 2 January 9th, 2007 08:28 AM
Invalid postback or callback argument. kingw BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 January 1st, 2007 09:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.