Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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 May 9th, 2010, 06:32 AM
Authorized User
 
Join Date: Jul 2009
Posts: 61
Thanks: 15
Thanked 1 Time in 1 Post
Default Problem with FileUpload

Hi,
I am trying to adapt the information in Chapter 13 to provide a simple file upload in a details view.
I am not using Linq - just using the info on pages 461 and on to adapt my exisiting code - perhaps that the problem?
Any way. I have :
Code:
<asp:DetailsView ID="DetailsView1" 
                       runat="server" 
                       Height="50px" 
                       Width="434px" 
                       AutoGenerateRows="False" 
                       DataKeyNames="RecordID" 
                       DataSourceID="SqlDataSource1" 
                       DefaultMode="Insert" >
        <Fields>
          Various <asp:templatefield> entries not relevant to the problem
          
          <asp:TemplateField HeaderText="Minutes">
             <EdititemTemplate>
            .................................nothing in here yet. When the Insertt works just adding the same stuff in with a sub for detailsview.itemediting???
            </EdititemTemplate> 
            <InsertItemTemplate>
                 <asp:FileUpLoad id="FileUpLoad1"  runat="server" />
                <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Please select a PDF file for upload" Text="*"></asp:CustomValidator>
                <asp:Button ID="cancelButton" height="20px" runat="server" CommandName="cancel" Text="Clear" CausesValidation="false" />
                <asp:Button id="Button1" Text="Upload" OnClick="Button1_Click" runat="server" Height="20px" CausesValidation="False" />
            </InsertItemTemplate>
          </asp:TemplateField>
          
          
          <asp:BoundField DataField="Agenda" HeaderText="Agenda"   SortExpression="Agenda" />
          
          <asp:BoundField DataField="Newsletter" HeaderText="Newsletter"  SortExpression="Newsletter" />
          <asp:BoundField DataField="Directory" HeaderText="Directory"  SortExpression="Directory" Visible="false" />

          <asp:CommandField ShowEditButton="True" ShowInsertButton="True"/>
        </Fields>
      </asp:DetailsView>
My VB code behind:
Code:
Partial Class Management_DocumentsAddEdit
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Request.QueryString.Get("Id") IsNot Nothing Then
            DetailsView1.DefaultMode = DetailsViewMode.Edit
        End If
    End Sub
    Private Sub EndEditing()
        Response.Redirect("DocumentsSelect.aspx")
    End Sub
    Protected Sub DetailsView1_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles DetailsView1.ItemInserted
        EndEditing()
    End Sub

    Protected Sub DetailsView1_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs) Handles DetailsView1.ItemUpdated
        EndEditing()
    End Sub

    Protected Sub Button1_Click (ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles DetailsView1.ItemInserting
        Dim fileupload1 As FileUpload = CType(DetailsView1.InsertItem.FindControl("FileUpload1"), FileUpload)
        If Not fileupload1.HasFile OrElse _
                Not fileupload1.FileName.ToLower().EndsWith("*.pdf") Then
            Dim CustomValidator1 As CustomValidator = _
                CType(DetailsView1.InsertItem.findcontrol("customvalidator1"), CustomValidator)
            CustomValidator1.IsValid = False
            e.Cancel = True
        End If
        fileupload1.SaveAs(Server.MapPath("~\Members Documents\" & fileupload1.FileName))
    End Sub


End Class
I am getting the following error when I use F5 to build the site:
Error 1 Argument not specified for parameter 'causesValidation' of 'Public Overridable Sub InsertItem(causesValidation As Boolean)'. C:\Websites\Cobham-ChamberOfCommerce\Management\DocumentsAddEdit.aspx .vb 21 47 C:\Websites\Cobham-ChamberOfCommerce\
Error 2 Argument not specified for parameter 'causesValidation' of 'Public Overridable Sub InsertItem(causesValidation As Boolean)'. C:\Websites\Cobham-ChamberOfCommerce\Management\DocumentsAddEdit.aspx .vb 25 23 C:\Websites\Cobham-ChamberOfCommerce\


I saw the bit in para 4 about setting 'causes validation' to false for the cancel button but I do not have a cancel button?
If I get this to work I plan to replicate it for the Agenda and Newsletter fields in the details view.
Do I need to use Fileupload2 and FileUpload3 and have separate subs for them in the code behind page?
__________________
Geoff Baldwin

Last edited by SouthendSupporter; May 9th, 2010 at 06:40 AM.. Reason: Clarification
 
Old May 9th, 2010, 07:45 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

On the ListView, InsertItem is a property that provides access to the item used to insert new data. On the DetailsView, InsertItem is a method that is used to trigger the insert action. You can see the difference by looking at the icons for the members in IntelliSense.

For the DetailsView, you can just directly access its controls like this:

Code:
 
Dim fileupload1 As FileUpload = CType(DetailsView1.FindControl("FileUpload1"), FileUpload)
Also, take a look at your Click handler for Button1. An argument as ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventAr gs doesn't make sense for the button. Instead you need something like this:

Code:
 
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
FileUpload msomar C# 2008 aka C# 3.0 5 April 12th, 2010 04:44 PM
Fileupload in Ajax bobwith5 ASP.NET 2.0 Professional 3 October 18th, 2008 09:59 AM
Problem to implement CSSClas on fileupload control azizur123 ASP.NET 2.0 Professional 1 October 13th, 2008 09:50 AM
Wierd asp:FileUpload problem rstelma ASP.NET 2.0 Professional 4 July 12th, 2008 05:31 AM
problem with FileUpload and request Parameters sira Servlets 1 July 22nd, 2006 09:32 PM





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