Click here to Skip to main content
15,900,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,
I am getting stuck inside this problem,

Here is my simple application using Master Page Concept and created one simple Page. which contains AsyncFileUpload Control and Submit Button

Code Page :

VB
Partial Class Pages_ArtWork_UploadImages
    Inherits BasePage

    Public imgFilePath As String = Nothing

.....

Protected Sub imgFileUpload_UploadedComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs)
        System.Threading.Thread.Sleep(1500)
        If imgFileUpload.HasFile Then
            If checkFileType(System.IO.Path.GetExtension(e.filename)) Then

                ' Getting the stream of the selected image and assign it to the Image Object.
                Dim UploadedImage As System.Drawing.Image = System.Drawing.Image.FromStream(imgFileUpload.PostedFile.InputStream)
                ' Checking if the Width or height is greater than 250px
                If UploadedImage.PhysicalDimension.Width > 250 OrElse UploadedImage.PhysicalDimension.Height > 250 Then
                    Dim alert As String = ("alert('Image size should be exactly 250*250 dimension. Your Current Image width is " + UploadedImage.PhysicalDimension.Width.ToString + " and height is " + UploadedImage.PhysicalDimension.Height.ToString + ".');")
                    ScriptManager.RegisterStartupScript(Me, [GetType](), "JScript", alert, True)
                Else
                    'Save File in Application.
                    imgFilePath = Server.MapPath("../../Uploads/Images/") + (ddl_EditHw.SelectedValue & System.IO.Path.GetExtension(e.filename))
                    imgFileUpload.SaveAs(imgFilePath)
                    lblResult.Visible = False
                    ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "Script", "alert('File Uploaded Successfully');", True)
                End If
            Else
                ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "Script", "alert('Uploading Failed - Check File Type (.jpg, .png, .gif, .jpeg)');", True)
            End If
        End If
        ClearContents(sender)
        
    End Sub

Public Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

        If Not imgFilePath = Nothing Then

....
...
     Else
      lblResult.Text = "Please Upload Image first."
            lblResult.Visible = True

        End If


In above submit click event , when I try to get Image File path from imgFilePath variable. It returns "Nothing". If I use same variable inside other functions It works perfectly. but dont know what is problem with Click event.
Waiting for your kind reply.

Thanking You


Regards :
Rohit More
Posted
Updated 5-Aug-13 23:15pm
v4

1 solution

Hi Rohit More,

use hidden field for this purpose

set value in hidden field and the get when required.
 
Share this answer
 
Comments
Rohit More 26-Aug-13 5:11am    
Thank you for your kind reply Mr.Prafulhk,
yeah I can solve this problem with using hidden field. but its alternative. Actually, I didnt get this thing that why class member variable loosing its values when submitting form.

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