Problems deleting files on server using asp.net

kco1122

Member
Joined
Mar 29, 2006
Messages
21
Programming Experience
5-10
Hello Folks!

I've created an upload utility for some of our editors that allows them to post up various media files to a media server. I've also created a management ui for them to view the files and info, etc.. My only problem now is giving them the ability to delete the same said files as they feel is necessary.

I'm using a DataList

HTML:
  <asp:DataList id="PictureFiles" Runat="Server"
  RepeatColumns="1"
  CellPadding="3"
  OnItemCommand="Delete_File" RepeatLayout="Flow" ShowFooter="False" ShowHeader="False">

        <ItemTemplate>
            <asp:Label ID="Label1" Text='<%# Container.DataItem %>' Runat="Server"/>
            <asp:Button ID="Button1" Text="Delete" Runat="Server" Font-Size="7pt" CommandName='<%# Container.DataItem %>'/>
        </ItemTemplate>
</asp:DataList>
You can see that when I click on Delete, its supposed to trigger this sub call:

VB.NET:
    Sub Delete_File(ByVal Src As Object, ByVal Args As DataListCommandEventArgs)
        File.Delete(Server.MapPath("Podcasts") & "\" & Args.CommandName)
        Bind_Picture_Files()
    End Sub

My problem is that whenever I try this, I get a server error about a postback error (the error is a bit long but here it is):

Server Error in '/WebSite' Application.
--------------------------------------------------------------------------------

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.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: 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.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[ArgumentException: 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.]
System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +2127900
System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +106
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +32
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
I don't see anything about postback being allowed on this control or what exactly this may mean that I'm doing wrong. Can anyone assist please?
 
Last edited by a moderator:
NM.. I've resolved this issue.. I didn't exactly fix the problem outright.. but I found that if i used a <asp:linkbutton... vs. a <asp:button..., everything worked fine. So I went with that.. never figured out why the button wouldn't work. If anyone has any thoughts I'd be glad to hear them as I would still prefer having an actual button.

Now onto another problem...
 
That error results when posting back from a dynamically created control.
If you had rebound the data-list, the control would be available for postback.

It is sometimes a timing issue at times :) You may have rebound the control AFTER the post-back attempt, or the control was created with a different ID.
 
Back
Top