Click here to Skip to main content
15,904,416 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I am using the file upload button inside the update panel. While running the running the program first time it returns false. After that it works fine. I have added the button in post back trigger. Is there any solution for this issue. Here is the code:

VB
Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try

            If Not myFileUpload.HasFile Then
                lblmsg.Text = "Please select the Excel file to Import"
                myFileUpload.Focus()
                Exit Sub
            End If

End sub
Posted

Hi,

I found the answer for this issue. Please add the below code to solve the problem.

VB
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        Dim Form As HtmlForm = Page.Form
        If Form.Enctype.Length = 0 Then
            Form.Enctype = "multipart/form-data"
        End If
    End Sub
 
Share this answer
 
 
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