以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  TextBox 问题  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=22131)

--  作者:cdzjs
--  发布时间:2012/8/3 12:47:00
--  TextBox 问题

这段代码文本框不输入内容就会报错

Dim txtName As WinForm.TextBox = e.Form.Controls("TextBox1")
Dim strName As String = txtName.Value

If strName.Length < 2 Then
    MessageBox.Show("姓名不能少于2个字符")
    Return
End If

加上判断了就不会了

Dim txtName As WinForm.TextBox = e.Form.Controls("TextBox1")
Dim strName As String = txtName.Value

If strName IsNot Nothing Then
    If strName.Length < 2 Then
       MessageBox.Show("姓名不能少于2个字符")
       Return
    End If
End If

 

这个是BUG还是?


--  作者:mr725
--  发布时间:2012/8/3 13:01:00
--  

当然要加判断呀,不然 If strName.Length < 2 Then 怎么成立呢?


--  作者:cdzjs
--  发布时间:2012/8/3 13:08:00
--  
主要是 这个 txtName.Value 默认居然不是""而是NOTHING
--  作者:blackzhu
--  发布时间:2012/8/3 14:08:00
--  
不应该呀  可以是  =""  或者>""  都可以的呀.

你可以试试这样?

Dim txtName As String = e.Form.Controls("TextBox1").Value
  if txtName > "" then
[此贴子已经被作者于2012-8-3 14:09:10编辑过]