Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can't figure this out.
Here is my code:
HTML
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm2.aspx.vb" Inherits="PDFRequesting.WebForm2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajaxToolkit:ToolkitScriptManager>
    <div>

        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>


        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>


        <ajaxToolkit:AsyncFileUpload ID="AsyncFileUpload1" runat="server" />
    <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
    </form>
</body>
</html>


And here is my code behind:
VB
Imports AjaxControlToolkit

Public Class WebForm2
    Inherits System.Web.UI.Page
    Dim VerifyError As Boolean

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'If first time page is submitted and we have file in FileUpload control but not in session 
        ' Store the values to SEssion Object 
        If ((Session("FileUpload23") Is Nothing) AndAlso AsyncFileUpload1.HasFile) Then
            Session("FileUpload23") = AsyncFileUpload1
            Label1.Text = AsyncFileUpload1.FileName

            ' Next time submit and Session has values but FileUpload is Blank 
            ' Return the values from session to FileUpload 
        ElseIf ((Not (Session("FileUpload23")) Is Nothing) AndAlso Not AsyncFileUpload1.HasFile) Then
            AsyncFileUpload1 = CType(Session("FileUpload23"), AsyncFileUpload)
            Label1.Text = AsyncFileUpload1.FileName

            ' Now there could be another sictution when Session has File but user want to change the file 
            ' In this case we have to change the file in session object 
        ElseIf AsyncFileUpload1.HasFile Then
            Session("FileUpload23") = AsyncFileUpload1
            Label1.Text = AsyncFileUpload1.FileName
        End If

    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If Verify() Then
        Else
            Label1.Text = "Error"

            AsyncFileUpload1 = Session("FileUpload23")
        End If

    End Sub

    Protected Function Verify() As Boolean
        Verify = True
        If TextBox1.Text = Nothing Then
            Verify = False
        End If
        Return Verify

    End Function
End Class


I have seen this example on the net but I can't get it to work. Every time I click on the button and an error is found(No Text in the Textbox) the page refreshes and I lose my file in the AsyncFileUpload. I have tried with the old FileUpload and the I get the same results.
What am I missing?

Thank you
Posted
Updated 21-Jan-15 16:15pm
v2

1 solution

you need to save file on OnUploadedComplete event,
refer below tutorial Using ASP.Net AJAX Control Toolkits AsyncFileUpload Control[^]
and CP article : AsyncFileUpload Control - New Control in Ajax Control ToolKit[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900