如何验证文本框+下拉菜单在VB中的asp.net形式 [英] How to Validate a textbox+dropdowns in vb for a asp.net form

查看:107
本文介绍了如何验证文本框+下拉菜单在VB中的asp.net形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

previous问题,它链接到这一点,并有任何增加code REF我忘了链接任何,我已经设置它给我发电子邮件应该有人提交此表,一个错误发生,现在如果他们无法验证,然后它会显示我的电子邮件,其中字段应该发生的最整数或日期时间字段失败,什么是输入到他们。

我现在有问题是验证以同样的方式在下拉菜单和textboxs什么,我整数和日期时间字段,所以我可以的情况下,显示这些也是在电子邮件,他们的错误。

present整数和日期时间验证

 抓住EX为例外
            lblInformation.Text =(< H4>无法保存在数据库&LT数据; / H4>+ vbNewLine +的错误是'+ ex.Message +'+ vbNewLine + vbNewLine + vbNewLine +的SQL命令,该命令falied是:+ vbNewLine +<强>中+ MYSQL +< / STRONG>中+ vbNewLine).Replace(vbNewLine,< BR />中+ vbNewLine)DIM DTB为DATETIME
            如果不DateTime.TryParse(DATEOFBIRTH,DTB)然后
                strEMessageBody.Append(<强>出生日期:< / STRONG>中和放大器; DateOfBirthYear.SelectedItem.Value&安培; - &放大器; DateOfBirthMonth.SelectedItem.Value&安培; - &放大器; DateOfBirthDay.SelectedItem.Value &放大器; vbCrLf)
                strEMessageBody.Append(< BR />中和放大器; vbTab&安培; vbTab&安培; vbTab&安培; vbTab&安培; vbTab&安培; vbTab)
            万一
DIM IAO作为整数
            如果不Integer.TryParse(电气特性的,IAO)然后
                strEMessageBody.Append(<强>的任何其它:< / STRONG>中和放大器; rblAnyOther.Text&放大器; vbCrLf)
                strEMessageBody.Append(< BR />中和放大器; vbTab&安培; vbTab&安培; vbTab&安培; vbTab&安培; vbTab&安培; vbTab)
            万一

然后最终验证下面我有昏暗的电子邮件设置,但我在其他的问题解决了。

问题是早得多页面我有

 子Upload_Click(来源BYVAL作为对象,BYVAL E上的EventArgs)
    如果(Page.IsValid)然后
        昏暗的名称作为字符串

其中$ P $只是用如上图所示,在这里我反而称他们别的东西,但这并不用绳子所以我的主要问题是有code的某些位检查,如果字符串在那里工作的名称pvents我是有效的,为此要么工作,但总是显示数据在电子邮件或code会打嗝的下拉菜单,

 昏暗的IMD作为整数
            如果不Integer.TryParse(部,IMD)然后
                strEMessageBody.Append(<强>部:< / STRONG>中和放大器; dept.Text&放大器; vbCrLf)
                strEMessageBody.Append(< BR />中和放大器; vbTab&安培; vbTab&安培; vbTab&安培; vbTab&安培; vbTab&安培; vbTab)
            万一

下面

是它是如何被设置录制部门
    部= dept.SelectedItem.Value
            部=替换(部门,','')

摘要: - 需要VB code,以验证是否字符串和下拉列表是有效的,使用try / catch块的是另一种可能的解决办法,但我无法弄清楚如何可以实施该验证<。 / p>

解决方案

由于放弃了试图找到一个解决办法,然后我只是戈纳关闭这个话题这篇文章作为回答各位。

Previous question which links onto this and has any addition code ref should I forget to link any, I have set it up to email me should someone submit this form and an error occur and right now should that occur for most integer or datetime fields if they fail to validate then it will show me which fields in the email failed and what was input into them.

Problem I'm having now is to validate the drop downs and the textboxs in a similar way to what I with integer and datetime fields so I can display those also in the email in case they error.

present integer and datetime validation

Catch ex As Exception
            lblInformation.Text = ("<h4>Unable to save data in database</h4>" + vbNewLine + "The error was '" + ex.Message + "'" + vbNewLine + vbNewLine + vbNewLine + "The SQL Command which falied was:" + vbNewLine + "<strong>" + mySQL + "</strong>" + vbNewLine).Replace(vbNewLine, "<br />" + vbNewLine)

Dim dtb As DateTime
            If Not DateTime.TryParse(DateOfBirth, dtb) Then
                strEMessageBody.Append("<strong>Date Of Birth:</strong> " & DateOfBirthYear.SelectedItem.Value & "-" & DateOfBirthMonth.SelectedItem.Value & "-" & DateOfBirthDay.SelectedItem.Value & vbCrLf)
                strEMessageBody.Append("<br/>" & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab)
            End If
Dim iao As Integer
            If Not Integer.TryParse(AnyOther, iao) Then
                strEMessageBody.Append("<strong>Any Other:</strong> " & rblAnyOther.Text & vbCrLf)
                strEMessageBody.Append("<br/>" & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab)
            End If

then below the final validation I have the Dim for the email setting but that I sorted out in the other question.

The problem is much earlier in the page I have

Sub Upload_Click(ByVal source As Object, ByVal e As EventArgs)
    If (Page.IsValid) Then
        Dim Name As String

Which prevents me just using there names as shown above where I would instead call them something else but that doesn't work with strings so my main issue is having some bit of code to check if the strings are valid and for the dropdowns which would either work but always show the data in the email or would hiccup in the code,

Dim imd As Integer
            If Not Integer.TryParse(dept, imd) Then
                strEMessageBody.Append("<strong>Department:</strong> " & dept.Text & vbCrLf)
                strEMessageBody.Append("<br/>" & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab)
            End If

below was how it had been setup to record the department Department = dept.SelectedItem.Value Department = Replace(Department, "'", "''")

Summary:- Need vb code to validate if strings and dropdowns are valid and the use of try/catch block is another possible solution but I wasn't able to figure out how to implement validation for that either.

解决方案

Since everybodies given up trying to find a solution then I'm just gona close this topic with this post as the answer.

这篇关于如何验证文本框+下拉菜单在VB中的asp.net形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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