如何在不使用ASP.NET验证器或VB.NET消息框的情况下使用标签验证文件上载? [英] How to validate file upload using labels without using ASP.NET validators or VB.NET message boxes?

查看:63
本文介绍了如何在不使用ASP.NET验证器或VB.NET消息框的情况下使用标签验证文件上载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码的问题在于验证但不会停止页面继续更新



我尝试过: < br $>


 dataFile = Server.MapPath(〜/ Documents / ids /& memberno&。pdf)

If File.Exists(dataFile)Then
Else

txtfileuploaderror2.Text =ID document is a required field
txtfileuploaderror2.Focus()
End如果



dataFile2 = Server.MapPath(〜/ Documents / MeansTests /& memberno&。pdf)
If File.Exists( dataFile2)然后
否则
txtfileuploaderror4.Text =表示测试是必填字段

txtfileuploaderror4.Focus()

结束如果



dataFile3 = Server.MapPath(〜/ Documents / Contracts /& memberno&。pdf)
If File.Exists(dataFile3)Then
否则
txtfileuploaderror3.Text =合同副本是必填字段

txtfileuploaderror3.Focus()
'退出子
结束如果

解决方案

您没有对缺少数据的信息做任何事情。你可以这样做。

 dataFile = Server.MapPath( 〜/ Documents / ids /& memberno&  。pdf
dataFile2 = Server.MapPath( 〜/ Documents / MeansTests /& ; memberno& 。pdf
dataFile3 = Server.MapPath( 〜/ Documents / Contracts /& memberno& 。pdf

如果 File.Exists(dataFile)然后
txtfileuploaderror2.Text = ID文档是必填字段
txtfileuploa derror2.Focus()
退出 Sub
结束 如果

如果 File.Exists(dataFile2)然后
txtfileuploaderror4.Text = 表示测试是必填字段
txtfileuploaderror4.Focus()
退出 Sub
结束 如果

如果 File.Exists(dataFile3)然后
txtfileuploaderror3.Text = 合同副本是一个必填字段
txtfileuploaderror3.Focus()
退出 Sub
结束 < span class =code-keyword>如果

Rest 更新代码





但如果有多个问题,你应该尽快让用户知道所有这些问题,例如

 dataFile = Server.MapPath( 〜/ Documents / ids /&会员和 。pdf
dataFile2 = Server.MapPath( 〜/ Documents / MeansTests /& memberno& < span class =code-string>。pdf)
dataFile3 = Server.MapPath( 〜/ Documents / Contracts /& memberno& 。pdf

Dim ok As Boolean = True

如果 File.Exists(dataFile)然后
txtfileuploaderror2.Text = ID文档是必填字段
txtfileuploaderror2.Focus ()
ok = False
结束 如果

如果 File.Exists(dataFile2 )然后
txtfileuploaderror4.Text = 表示测试是必填字段
txtfileuploaderror4.Focus()
ok = False
结束 如果

如果 File.Exists(dataFile3)然后
txtfileuploaderror3.Text = 合同副本是必填字段
txtfileuploaderror3.Focus()
ok = 错误
结束 如果

如果 ok 然后
退出 Sub
结束 如果

' 其他更新代码


The problem with this code is it validate but doesn't stop page to continue with updating

What I have tried:

dataFile = Server.MapPath("~/Documents/ids/" & memberno & ".pdf")

          If File.Exists(dataFile) Then
          Else

              txtfileuploaderror2.Text = "ID document is a required field"
              txtfileuploaderror2.Focus()
          End If



          dataFile2 = Server.MapPath("~/Documents/MeansTests/" & memberno & ".pdf")
          If File.Exists(dataFile2) Then
          Else
              txtfileuploaderror4.Text = "Means Test is a required field"

              txtfileuploaderror4.Focus()

          End If



          dataFile3 = Server.MapPath("~/Documents/Contracts/" & memberno & ".pdf")
          If File.Exists(dataFile3) Then
          Else
              txtfileuploaderror3.Text = "Copy of Contract is a required field"

              txtfileuploaderror3.Focus()
              'Exit Sub
          End If

解决方案

You are not doing anything with the information that there is missing data. YOu could do it like this.

dataFile = Server.MapPath("~/Documents/ids/" & memberno & ".pdf")
dataFile2 = Server.MapPath("~/Documents/MeansTests/" & memberno & ".pdf")
dataFile3 = Server.MapPath("~/Documents/Contracts/" & memberno & ".pdf")

If Not File.Exists(dataFile) Then
    txtfileuploaderror2.Text = "ID document is a required field"
    txtfileuploaderror2.Focus()
    Exit Sub
End If

If Not File.Exists(dataFile2) Then
    txtfileuploaderror4.Text = "Means Test is a required field"
    txtfileuploaderror4.Focus()
    Exit Sub
End If

If Not File.Exists(dataFile3) Then
    txtfileuploaderror3.Text = "Copy of Contract is a required field"
    txtfileuploaderror3.Focus()
    Exit Sub
End If

Rest of update code



But if there is more than one problem you should really let the user know about all of them as soon as possible e.g

dataFile = Server.MapPath("~/Documents/ids/" & memberno & ".pdf")
dataFile2 = Server.MapPath("~/Documents/MeansTests/" & memberno & ".pdf")
dataFile3 = Server.MapPath("~/Documents/Contracts/" & memberno & ".pdf")

Dim ok As Boolean = True

If Not File.Exists(dataFile) Then
    txtfileuploaderror2.Text = "ID document is a required field"
    txtfileuploaderror2.Focus()
    ok = False
End If

If Not File.Exists(dataFile2) Then
    txtfileuploaderror4.Text = "Means Test is a required field"
    txtfileuploaderror4.Focus()
    ok = False
End If

If Not File.Exists(dataFile3) Then
    txtfileuploaderror3.Text = "Copy of Contract is a required field"
    txtfileuploaderror3.Focus()
    ok = False
End If

If Not ok Then
    Exit Sub
End If

'Rest of update code


这篇关于如何在不使用ASP.NET验证器或VB.NET消息框的情况下使用标签验证文件上载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆