S
shapper
Hello,
I created nested pages as follows:
Base.master
| ------ Global.master
| ------ TwoColumns.master
| ------ Default.aspx
In Global.master.vb I added a textbox in runtime:
1 Protected WithEvents tbUsername As New TextBox
2 cphGlobal.Controls.Add(tbUsername)
In Global.master.vb I also added a a button at runtime where I want to
access tbUsername when the button is clicked:
1 Private Sub ibSubmit_Click(ByVal sender As Object, ByVal e As
ImageClickEventArgs) Handles ibSubmit.Click
2
3 Dim ibSubmit As ImageButton = CType(sender, ImageButton)
4
5 Dim tbUsername As TextBox =
CType(Page.FindControl("tbUsername"), TextBox)
6 If String.IsNullOrEmpty(tbUsername.Text) Then
7 tbUsername.CssClass = "tbSystemError"
8 End If
9
10 End Sub
When I click the button I get the error, on line 6:
"Object reference not set to an instance of an object."
I tried many variations of my code. For example:
1 Dim tbUsername As TextBox = CType(Page.FindControl("tbUsername"),
TextBox)
However, I am not able to make this work.
Could someone, please, help me out?
I don't know what else to do.
Thanks,
Miguel
I created nested pages as follows:
Base.master
| ------ Global.master
| ------ TwoColumns.master
| ------ Default.aspx
In Global.master.vb I added a textbox in runtime:
1 Protected WithEvents tbUsername As New TextBox
2 cphGlobal.Controls.Add(tbUsername)
In Global.master.vb I also added a a button at runtime where I want to
access tbUsername when the button is clicked:
1 Private Sub ibSubmit_Click(ByVal sender As Object, ByVal e As
ImageClickEventArgs) Handles ibSubmit.Click
2
3 Dim ibSubmit As ImageButton = CType(sender, ImageButton)
4
5 Dim tbUsername As TextBox =
CType(Page.FindControl("tbUsername"), TextBox)
6 If String.IsNullOrEmpty(tbUsername.Text) Then
7 tbUsername.CssClass = "tbSystemError"
8 End If
9
10 End Sub
When I click the button I get the error, on line 6:
"Object reference not set to an instance of an object."
I tried many variations of my code. For example:
1 Dim tbUsername As TextBox = CType(Page.FindControl("tbUsername"),
TextBox)
However, I am not able to make this work.
Could someone, please, help me out?
I don't know what else to do.
Thanks,
Miguel