Do not use on any
shared computer
August 29, 2008 02:58pm pdt
 
[x]
Attachment Details

Difference between DataList and GridView - Handling an item delete

Tags: vb.net 2.0, IE, Invalid Postback or Callback argument.
I can't seem to work out why the Invalid Postback error is showing up.  I have a page with a UpdatePanel.  In that panel I have tried two different types of controls (independently - in other words, I don't need to make both of these work at the same time - I want the Datalist, but it is not working the same as the GridView and I can't figure out why that is).  

One is a GridView control, and one is a DataList control.  I have bound both controls to the same data source and they both display just fine.  The issue comes when I want to handle a command.  In the GridView, if I put a column with a ImageButton and wire up the click event to my code behind, everything works as expected.  When I switch to a DataList and try the same "approach" I get the client-side error regarding "Invalid Postback or Callback....".

Please take a look at my DataList version of this.  Is there something glaringly wrong here?  I do not want to disable EventValidation.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
---Update Panel on .aspx page----
    <asp:UpdatePanel ID="filePanel" updateMode="Conditional" runat="server">
        <ContentTemplate>
            <div style="width: 450px; height: 300px; overflow-y: auto; overflow-x: hidden; padding: 5px;">
                <asp:DataList ID="FileList" runat="server" DataKeyField="FileName">
                    <ItemTemplate>
                        <div style="float: left; width: 185px;border: dotted 1px #c9c9c9;text-align: center; vertical-align:middle;margin: 2px; padding: 4px 0px 4px 0px;">
                            <asp:ImageButton 
                                ID="PicDelete" 
                                runat="server" CommandName="delete"
                                ImageUrl="img/delete_icon.gif" />
                            <i><%#Eval("LighteningFileType")%><br /></i>
                            <cc1:ConfirmButtonExtender ID="ConfirmButtonExtender2" TargetControlID="PicDelete" ConfirmText="This cannot be undone.  Are you sure?" runat="server" />
                            <a href="javascript: showPopImage('<%# Eval("FileGUID") %>', <%# Eval("LighteningFileTypeID") %>)">
                               <asp:Image 
                                    ID="Image1"
                                    runat="server" 
                                    Width='<%#getImageWidth(Eval("LighteningFileTypeID")) %>' 
                                    ImageUrl='<%# getImageUrl(Eval("LighteningFileTypeID"), Eval("FileExtension").ToString(), Eval("FileGUID").ToString()) %>' 
                                    AlternateText='<%# Eval("FileName") %>'/>
                            </a>
                            <asp:Label ID="filetype" Text='<%# FileNamePresentation(Eval("LighteningFileTypeID"), Eval("FileName"), Eval("FileGUID").ToString()) %>' 
                                runat="server"/>
                        </div>
                    </ItemTemplate>
                </asp:DataList></div>
        </ContentTemplate>
    </asp:UpdatePanel>
 
 
 
 
 
 
----event handler in code-behind .aspx.vb page---------
 
    Protected Sub PictureDelete(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles FileList.ItemCommand
        If e.CommandName = "delete" Then
            Dim fguid As String = FileList.DataKeys(e.Item.ItemIndex).Value.ToString()
 
            Dim lf As New LightningFixes()
            lf.DeleteLightingFile(fguid)
 
            'this removes the file from the FileStoreWebService database
            Dim fd As New DeleteFileFromWebService(fguid)
            lf.GetALLLightningFiles(_pid)
            filePanel.Update()
            If lf.LightningFiles.Tables(0).Rows.Count <> 0 Then
                hideShowFileSections("show")
            Else
                Response.Redirect("Lightning.aspx?ProjectID=" & _pid)
            End If
        End If
 
    End Sub
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Programming
Question Asked By: skrile
Solution Provided By: G0ggy
Participating Experts: 1
Solution Grade: A
Views: 97
Translate:
Loading Advertisement...
 
[+][-]Author Comment by skrile
Author Comment by skrile:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Accepted Solution by G0ggy

Rank: Guru

Accepted Solution by G0ggy:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by skrile
Author Comment by skrile:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_2_20070628