全局/类变量值在同一类中的按钮单击事件内被跳过 [英] Global / Class variable value is getting skipped inside button click event in same class
问题描述
Hello Everyone,
我遇到了这个问题,
这是我使用母版页概念的简单应用程序并创建了一个简单的页面。其中包含AsyncFileUpload控件和提交按钮
代码页:
部分 类 Pages_ArtWork_UploadImages
继承 BasePage
公共 imgFilePath 作为 字符串 = 没有
.....
受保护的 Sub imgFileUpload_UploadedComplete( ByVal sender 正如 对象, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs)
System.Threading.Thread.Sleep( 1500 )
如果 imgFileUpload.HasFile 那么
如果 checkFileType(System.IO。 Path.GetExtension(e.filename))然后
' 获取所选图像的流并将其分配给图像对象。
Dim UploadedImage As System.Drawing.Image = System.Drawing.Image.FromStream(imgFileUpload.PostedFile.InputStream)
' 检查宽度或高度是否大于250px
如果 UploadedImage.PhysicalDimension.Width> 250 OrElse UploadedImage.PhysicalDimension.Height> 250 然后
Dim 提醒作为 字符串 =( alert('图像大小应该精确为250 * 250维。当前图像宽度为 + UploadedImage.PhysicalDimension.Width.ToString + 和height为 + UploadedImage.PhysicalDimension.Height.ToString + 。');)
ScriptManager.RegisterStartupScript( Me ,[ GetType ](), JScript,alert, True )
否则
' 将文件保存在应用程序中。
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 (), 脚本, alert('File Uploadedfully');, True )
结束 如果
其他
ScriptManager .RegisterClientScriptBlock( Me , Me 。 GetType (), 脚本, alert('上传失败 - 检查文件类型(.jpg,.png,.gif,.jpeg)'); , True )
结束 如果
结束 如果
ClearContents(sender)
结束 Sub
公共 Sub btnSubmit_Click( ByVal sender 作为 对象, ByVal e As System.EventArgs)句柄 btnSubmit.Click
如果 < span class =code-keyword>不 imgFilePath = Nothing 然后
....
...
其他
lblResult.Text = 请先上传图片。
lblResult.Visible = True
结束 如果
在上面的提交点击事件中,当我尝试从imgFilePath变量获取图像文件路径时。它返回Nothing。如果我在其他函数中使用相同的变量它完美地工作。但不知道Click事件有什么问题。
等待您的回复。
感谢你
问候:
Rohit更多
您好Rohit More,< br $>
为此目的使用隐藏字段
隐藏字段中的设置值以及需要时获取。
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 :
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
Hi Rohit More,
use hidden field for this purpose
set value in hidden field and the get when required.
这篇关于全局/类变量值在同一类中的按钮单击事件内被跳过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!