473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Invalid postback or callback argument is driving me nuts!

Hi all experts,

I am going nuts with this Invalid postback or callback argument thingy
with .Net 2.0

I am building a file attachment module which relays on a Datatable
stored in session (yeah i know its unhealthy, but its the only "clean"
approach which I can think of to avoid tranfering temp files onto the
server) to maintain the list of attached files before the "commit"
action is done to transfer all the files onto the server.

I have a function which allows the user to delete the attached file
before the "commit" action is performed. Essentially, the "delete" is
deleting a row from the Datatable stored in session. When I was doing
testing of this code in the early phase, all works well, but suddenly a
few days later, when I improved the codes to incorporate other
functions, whenever I click on the "delete" button (which is a template
column with an image button that triggers a "RowCommand" to handle the
deletion) i will hit the Invalid postback error. I have since removed
those new codes but I am still stuck with the problem.

Someone help me please! I am totally clueless as how to resolve this
issue. I have tried to turn off the EnableEventValidation at the page
level, but when I do so, my "RowCommand" event is not being triggered
(it works fine if i turn on the validation). You guys see the
fustration I am facing here?

Would really really be glad if someone could help me. I have attached
my codes below so you guys can help me take a look. Do let me know if
you need more information.

------------- Code Behind ---------------

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Not IsPostBack Then
BindAttachmentGrid(True)
Else
BindAttachmentGrid(False)
End If
vldInvalidFile.Visible = False
vldLimitExceeded.Visible = False
vldDuplicate.Visible = False
End Sub

Private Sub BindAttachmentGrid(ByVal blnBindEmpty As Boolean)
Dim dt As DataTable
If blnBindEmpty = False Then
dt = Me.p_AttachmentTempStorage <-- "this
p_AttachmentTempStorage is a private property which will determine if
an existing DT is stored in the session, if not, it will call the
CreateAttachmentDT" -->
End If
gdvAttachment.DataSource = dt
gdvAttachment.DataBind()
End Sub

Private Sub CreateAttachmentDT()
Dim dtAttach As New DataTable
dtAttach.Columns.Add("ID", GetType(Integer))
dtAttach.Columns.Add("FileName", GetType(String))
dtAttach.Columns.Add("RawFileSize", GetType(Integer))
dtAttach.Columns.Add("FileSize", GetType(String))
dtAttach.Columns.Add("UploadedBy", GetType(String))
dtAttach.Columns.Add("UploadedDateTime", GetType(String))
dtAttach.Columns.Add("FileStream",
GetType(WebControls.FileUpload))
dtAttach.Columns.Add("FileTypeFlag", GetType(String))
dtAttach.Columns.Add("FilePath", GetType(String))
dtAttach.PrimaryKey = New DataColumn() {dtAttach.Columns("ID")}
Me.p_AttachmentTempStorage = dtAttach
End Sub

Protected Sub btnAttach_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnAttach.Click
If fileAttach.HasFile = True Then
Dim tmpTotalSize As Double = Me.p_TotalUploadedSize <--
"all Me.p_XXXX are simply private property which stores information in
viewstate" -->
tmpTotalSize += fileAttach.PostedFile.ContentLength
If tmpTotalSize 10485760 Then
vldLimitExceeded.Visible = True
Exit Sub
End If
If Me.p_AllowDuplication = False Then
For Each dRowItem As DataRow In
Me.p_AttachmentTempStorage.Rows
If dRowItem("FileName").ToString.Trim =
fileAttach.FileName Then
vldDuplicate.Visible = True
Exit Sub
End If
Next
End If
Dim dRow As DataRow
Me.p_TotalUploadedSize +=
fileAttach.PostedFile.ContentLength
dRow = Me.p_AttachmentTempStorage.NewRow()
Me.p_AttachmentID += 1
dRow("ID") = Me.p_AttachmentID
dRow("FileName") = fileAttach.FileName
dRow("RawFileSize") = fileAttach.PostedFile.ContentLength
dRow("FileSize") =
ConvertFileSize(fileAttach.PostedFile.ContentLengt h)
dRow("UploadedBy") =
clsUser.getUserName(clsUser.getEmployeeIDByLoginID (MyBase.GetLogonUser()))
dRow("UploadedDateTime") = Format(Now,
clsUtil.ConfigValue("dateTimeFormat"))
dRow("FileStream") = fileAttach
dRow("FileTypeFlag") = "New"
dRow("FilePath") = ""
Me.p_AttachmentTempStorage.Rows.Add(dRow)
Me.p_AttachmentTempStorage.AcceptChanges()
If gdvAttachment.PageCount <0 Then
gdvAttachment.PageIndex = gdvAttachment.PageCount
End If
BindAttachmentGrid(False)
Else
vldInvalidFile.Visible = True
End If

End Sub

Protected Sub gdvAttachment_RowDataBound(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
gdvAttachment.RowDataBound
If e.Row.RowType = DataControlRowType.Header Then
e.Row.Cells(2).Text = "Size <br>(" &
ConvertFileSize(Me.p_TotalUploadedSize) & " Total)"
ElseIf e.Row.RowType = DataControlRowType.DataRow Then
Dim lBtnFileName As LinkButton =
CType(e.Row.FindControl("lBtnFileName"), LinkButton)
lBtnFileName.CommandArgument = e.Row.DataItem("ID")
AddHandler lBtnFileName.Click, AddressOf lBtnFileName_Click
CType(e.Row.FindControl("btnAttachmentDelete"),
ImageButton).Attributes.Add("onclick", "return confirm('Are you sure
you want to delete " & e.Row.DataItem("FileName") & "?')")
CType(e.Row.FindControl("btnAttachmentDelete"),
ImageButton).CommandArgument = e.Row.DataItem("ID")
End If
End Sub

<-- "The following code suppose to be the one to handle the delete
event, but before this code is even run, I hit the above error
already!" -->
Protected Sub gdvAttachment_RowCommand(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs ) Handles
gdvAttachment.RowCommand
If e.CommandName = "CustomDelete" Then
Try
Dim dRow As DataRow =
Me.p_AttachmentTempStorage.Rows.Find(e.CommandArgu ment)
If dRow("FileTypeFlag") = "Existing" Then
If System.IO.File.Exists(dRow("FilePath")) = True
Then
System.IO.File.Delete(dRow("FilePath"))
End If
End If
Me.p_TotalUploadedSize -= dRow("RawFileSize")
Me.p_AttachmentTempStorage.Rows.Remove(dRow)
BindAttachmentGrid(False)
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End If
End Sub

By the way, the above codes are in a UserControl and the control is
place inside a plain aspx page.

Regards,
Jason

Nov 2 '06 #1
5 6841
Hello all.

Upon further research, I found my error was caused by the "Delete"
image button which resides in the template column of my gridview.

If i use a standard command button it works. But I need to use the
image button of coporate standard requirement!

Anyone have any idea how can i resolve this image button with grid view
problem?

I search the groups and found another thread start whom encounter the
same problem as me, including the fact when we disable the
"EnableEventValidation" function, the event for the RowCommand is not
triggering. Regretfully no one answered him.

Any idea anyone?

Nov 2 '06 #2
i have the same problem...
some news ???

jason wrote:
Hello all.

Upon further research, I found my error was caused by the "Delete"
image button which resides in the template column of my gridview.

If i use a standard command button it works. But I need to use the
image button of coporate standard requirement!

Anyone have any idea how can i resolve this image button with grid view
problem?

I search the groups and found another thread start whom encounter the
same problem as me, including the fact when we disable the
"EnableEventValidation" function, the event for the RowCommand is not
triggering. Regretfully no one answered him.

Any idea anyone?
Nov 3 '06 #3
hello any help anyone?

Nov 4 '06 #4
Just had the same problem. Found that I shouldn't do a DataBind() on
the LoadEvent. More details on my Blog (Shameless plug):
http://droyad.blogspot.com/2006/12/i...-argument.html

jason wrote:
hello any help anyone?
Dec 14 '06 #5
Just had the same problem. Found that I shouldn't do a DataBind() on
the LoadEvent. More details on my Blog (Shameless plug):
http://droyad.blogspot.com/2006/12/i...-argument.html

merco wrote:
i have the same problem...
some news ???

jason wrote:
Hello all.

Upon further research, I found my error was caused by the "Delete"
image button which resides in the template column of my gridview.

If i use a standard command button it works. But I need to use the
image button of coporate standard requirement!

Anyone have any idea how can i resolve this image button with grid view
problem?

I search the groups and found another thread start whom encounter the
same problem as me, including the fact when we disable the
"EnableEventValidation" function, the event for the RowCommand is not
triggering. Regretfully no one answered him.

Any idea anyone?
Dec 14 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JULO | last post by:
Hi, I have this problem: In GridView I have template column with ImageButtons - for deleting row. When I click on that button I get this message Invalid postback or callback argument. Event...
2
by: Ray Stevens | last post by:
Anyone see this error that appears to have cropped up with the RTM version of .NET: BASE EXCEPTION:: System.ArgumentException: Invalid postback or callback argument. Event validation is enabled...
1
by: Timbo | last post by:
Hi all, This is my first message here so i'll try and include all the information that will help you help me out, if possible. Basically I am using C# in ASP.NET 2.0 and have a Repeater...
3
by: Martin | last post by:
Hi, I have an aspx page with two dropdownlist controls. I update the options in the second ddl based on selection made in the first. I do this with the ICallbackEventHandler interface, as per...
2
by: Wizzard | last post by:
I have a repeater with and imagebutton on a page useing VS2005 ASP.Net 2.0 <asp:Repeater ID="Repeater1" runat="server" > <ItemTemplate> <div> <asp:ImageButton ImageUrl="button.gif"...
3
by: Nathan Sokalski | last post by:
I am recieving the following error on the second postback of a page I have written: The state information is invalid for this page and might be corrupted Stack Trace: ...
2
by: Nathan Sokalski | last post by:
I have a DataList in which the ItemTemplate contains two Button controls that use EventBubbling. When I click either of them I receive the following error: Server Error in '/' Application....
9
by: 200dogz | last post by:
Hi guys, I want to have a button which opens up a new window when pressed. <asp:Button ID="Button1" runat="server" Text="Open new window" /> ... Button1.Attributes.Add("OnClick",
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.