首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >System.NullReferenceException:对象引用没有设置为对象的实例。在试图存储文本框值时发生错误。

System.NullReferenceException:对象引用没有设置为对象的实例。在试图存储文本框值时发生错误。
EN

Stack Overflow用户
提问于 2016-06-15 20:36:07
回答 1查看 780关注 0票数 0

我想将文本框的文本存储到string变量中,但是出现了一个错误:

System.NullReferenceException:未设置为对象实例的对象引用

代码:

代码语言:javascript
复制
 Dim Name As String = txtName.Text
Dim Email As String = txtEmail.Text
Dim Password As String = txtPassword.Text
Dim Repassword As String = txtRepassword.Text
Dim Country As String = txtCountry.Text
Dim College As String = txtCollege.Text
Dim Phone As String = txtPhone.Text

它显示txtName.text为NULL;如何修复它?

我的控制代码在这里:

代码语言:javascript
复制
'''<summary>
'''txtName control.
'''</summary>
'''<remarks>
'''Auto-generated field.
'''To modify move field declaration from designer file to code-behind file.
'''</remarks>
Protected WithEvents txtName As Global.System.Web.UI.WebControls.TextBox
'''<summary>
'''txtEmail control.
'''</summary>
'''<remarks>
'''Auto-generated field.
'''To modify move field declaration from designer file to code-behind file.
'''</remarks>
Protected WithEvents txtEmail As Global.System.Web.UI.WebControls.TextBox
'''<summary>
'''txtPassword control.
'''</summary>
'''<remarks>
'''Auto-generated field.
'''To modify move field declaration from designer file to code-behind file.
'''</remarks>
Protected WithEvents txtPassword As Global.System.Web.UI.WebControls.TextBox
'''<summary>
'''txtRepasword control.
'''</summary>
'''<remarks>
'''Auto-generated field.
'''To modify move field declaration from designer file to code-behind file.
'''</remarks>
Protected WithEvents txtRepassword As Global.System.Web.UI.WebControls.TextBox
'''<summary>
'''txtCountry control.
'''</summary>
'''<remarks>
'''Auto-generated field.
'''To modify move field declaration from designer file to code-behind file.
'''</remarks>
Protected WithEvents txtCountry As Global.System.Web.UI.WebControls.TextBox
'''<summary>
'''txtCollege control.
'''</summary>
'''<remarks>
'''Auto-generated field.
'''To modify move field declaration from designer file to code-behind file.
'''</remarks>
Protected WithEvents txtCollege As Global.System.Web.UI.WebControls.TextBox
'''<summary>
'''txtPhone control.
'''</summary>
'''<remarks>
'''Auto-generated field.
'''To modify move field declaration from designer file to code-behind file.
'''</remarks>
Protected WithEvents txtPhone As Global.System.Web.UI.WebControls.TextBox
EN

回答 1

Stack Overflow用户

发布于 2016-06-16 02:24:52

一些错误检查将帮助您避免堆栈跟踪。

代码语言:javascript
复制
If String.IsNullOrEmpty(txtName.Text) Then
Dim name As String = txtName.Text
End If
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37845292

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档