I want to store textbox's text into string variable but an error occurs:
System.NullReferenceException: Object reference not set to an instance of an object
Code:
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
It shows that txtName.text
is NULL; how can I fix it?
My control code is here:
'''<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