我想将文本框的文本存储到string变量中,但是出现了一个错误:
System.NullReferenceException:未设置为对象实例的对象引用
代码:
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;如何修复它?
我的控制代码在这里:
'''<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发布于 2016-06-16 02:24:52
一些错误检查将帮助您避免堆栈跟踪。
If String.IsNullOrEmpty(txtName.Text) Then
Dim name As String = txtName.Text
End Ifhttps://stackoverflow.com/questions/37845292
复制相似问题