By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,192 Members | 1,276 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,192 IT Pros & Developers. It's quick & easy.

System.NullReferenceException on TextBox object...

P: n/a
Hello,

I am trying to set up a panel that appears on a page that prompts a user
to enter in a note. This panel object is initially invisable and appears
when the user clicks on a button. Contained within the panel are a couple
of buttons and a textbox. Code is as follows:

ASPX page:
---------

<%@ Page Language="VB" Inherits="CustProfile" Src="CustProfile.vb"
autoeventwireup="False" %>
<html>
<form>
....

<td align="middle">
<asp:Button id="btnAddNote" runat="server" Text="Add New
Note"></asp:Button>
</td>
....

<asp:Panel id="pnlAddNote" style="BORDER-RIGHT: black 1px solid; BORDER-TOP:
black 1px solid; Z-INDEX: 1; BACKGROUND: silver; LEFT: 210px; BORDER-LEFT:
black 1px solid; BORDER-BOTTOM: black 1px solid; POSITION: absolute; TOP:
265px" runat="server" Width="360px" Visible="False" HorizontalAlign="Left">
<p>
<strong>Add Note:</strong>
</p>
<p align="center">
<asp:TextBox id="txAddNote" runat="server" Columns="35"
AutoPostBack="True" Wrap="True" TextMode="MultiLine" Enabled="True"
Visible="True" Rows="4">Enter Note Here.</asp:TextBox>
</p>
<p align="center">
<asp:Button id="btnSaveNote" runat="server" Text="Save Note"
Enabled="True" Visible="True"></asp:Button>
&nbsp;
<asp:Button id="btnCancelNote" runat="server" Text="Cancel"
Enabled="True" Visible="True"></asp:Button>
<br />
<br />
</p>
</asp:Panel>
....
</form>
</html>
VB code:
-------
Imports ...

Public Class CustProfile
'For PostBack
Inherits Page

Protected txtAddNote as TextBox
Protected pnlAddNote as Panel
Protected WithEvents btnAddNote as Button
....

Private Sub btnAddNote_Click(source as Object, e as EventArgs) Handles
btnAddNote.Click
txtAddNote.Text = ""
pnlAddNote.Visible = True
End Sub

....
End Class
And this is the error message I get which makes no sense to me because the
object is declared and exists in both files.

Browser Msg:
-----------

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 422:
Line 423: Private Sub btnAddNote_Click(source as Object, e as EventArgs)
Handles btnAddNote.Click
Line 424: txtAddNote.Text = ""
Line 425: pnlAddNote.Visible = True
Line 426: End Sub

Source File: C:\Inetpub\wwwroot\incident\cust\CustProfile.vb Line: 424

If anyone can shed some light on this subject (namely point out what I'm
doing wrong) it would be greatly appreciated.

A. Nonymous (slightly dazed and confused)
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Please disregard this post.

I think I've found a way using JavaScript.
"A. Nonymous" <an*******@hotmail.com> wrote in message
news:2P********************@giganews.com...
Hello,

I am trying to set up a panel that appears on a page that prompts a user to enter in a note. This panel object is initially invisable and appears
when the user clicks on a button. Contained within the panel are a couple
of buttons and a textbox. Code is as follows:

ASPX page:
---------

<%@ Page Language="VB" Inherits="CustProfile" Src="CustProfile.vb"
autoeventwireup="False" %>
<html>
<form>
...

<td align="middle">
<asp:Button id="btnAddNote" runat="server" Text="Add New
Note"></asp:Button>
</td>
...

<asp:Panel id="pnlAddNote" style="BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; Z-INDEX: 1; BACKGROUND: silver; LEFT: 210px; BORDER-LEFT:
black 1px solid; BORDER-BOTTOM: black 1px solid; POSITION: absolute; TOP:
265px" runat="server" Width="360px" Visible="False" HorizontalAlign="Left"> <p>
<strong>Add Note:</strong>
</p>
<p align="center">
<asp:TextBox id="txAddNote" runat="server" Columns="35"
AutoPostBack="True" Wrap="True" TextMode="MultiLine" Enabled="True"
Visible="True" Rows="4">Enter Note Here.</asp:TextBox>
</p>
<p align="center">
<asp:Button id="btnSaveNote" runat="server" Text="Save Note" Enabled="True" Visible="True"></asp:Button>
&nbsp;
<asp:Button id="btnCancelNote" runat="server" Text="Cancel" Enabled="True" Visible="True"></asp:Button>
<br />
<br />
</p>
</asp:Panel>
...
</form>
</html>
VB code:
-------
Imports ...

Public Class CustProfile
'For PostBack
Inherits Page

Protected txtAddNote as TextBox
Protected pnlAddNote as Panel
Protected WithEvents btnAddNote as Button
...

Private Sub btnAddNote_Click(source as Object, e as EventArgs) Handles
btnAddNote.Click
txtAddNote.Text = ""
pnlAddNote.Visible = True
End Sub

...
End Class
And this is the error message I get which makes no sense to me because the
object is declared and exists in both files.

Browser Msg:
-----------

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 422:
Line 423: Private Sub btnAddNote_Click(source as Object, e as EventArgs) Handles btnAddNote.Click
Line 424: txtAddNote.Text = ""
Line 425: pnlAddNote.Visible = True
Line 426: End Sub

Source File: C:\Inetpub\wwwroot\incident\cust\CustProfile.vb Line: 424

If anyone can shed some light on this subject (namely point out what I'm
doing wrong) it would be greatly appreciated.

A. Nonymous (slightly dazed and confused)

Nov 19 '05 #2

P: n/a
I figured out the problem:

txtAddNote.Text = "" (empty string) causes the problem

I alternatively used:

txtAddNote.Text = " " (a space)

....and all is well.

Sigh!

"A. Nonymous" <an*******@hotmail.com> wrote in message
news:2P********************@giganews.com...
Hello,

I am trying to set up a panel that appears on a page that prompts a user to enter in a note. This panel object is initially invisable and appears
when the user clicks on a button. Contained within the panel are a couple
of buttons and a textbox. Code is as follows:

ASPX page:
---------

<%@ Page Language="VB" Inherits="CustProfile" Src="CustProfile.vb"
autoeventwireup="False" %>
<html>
<form>
...

<td align="middle">
<asp:Button id="btnAddNote" runat="server" Text="Add New
Note"></asp:Button>
</td>
...

<asp:Panel id="pnlAddNote" style="BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; Z-INDEX: 1; BACKGROUND: silver; LEFT: 210px; BORDER-LEFT:
black 1px solid; BORDER-BOTTOM: black 1px solid; POSITION: absolute; TOP:
265px" runat="server" Width="360px" Visible="False" HorizontalAlign="Left"> <p>
<strong>Add Note:</strong>
</p>
<p align="center">
<asp:TextBox id="txAddNote" runat="server" Columns="35"
AutoPostBack="True" Wrap="True" TextMode="MultiLine" Enabled="True"
Visible="True" Rows="4">Enter Note Here.</asp:TextBox>
</p>
<p align="center">
<asp:Button id="btnSaveNote" runat="server" Text="Save Note" Enabled="True" Visible="True"></asp:Button>
&nbsp;
<asp:Button id="btnCancelNote" runat="server" Text="Cancel" Enabled="True" Visible="True"></asp:Button>
<br />
<br />
</p>
</asp:Panel>
...
</form>
</html>
VB code:
-------
Imports ...

Public Class CustProfile
'For PostBack
Inherits Page

Protected txtAddNote as TextBox
Protected pnlAddNote as Panel
Protected WithEvents btnAddNote as Button
...

Private Sub btnAddNote_Click(source as Object, e as EventArgs) Handles
btnAddNote.Click
txtAddNote.Text = ""
pnlAddNote.Visible = True
End Sub

...
End Class
And this is the error message I get which makes no sense to me because the
object is declared and exists in both files.

Browser Msg:
-----------

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 422:
Line 423: Private Sub btnAddNote_Click(source as Object, e as EventArgs) Handles btnAddNote.Click
Line 424: txtAddNote.Text = ""
Line 425: pnlAddNote.Visible = True
Line 426: End Sub

Source File: C:\Inetpub\wwwroot\incident\cust\CustProfile.vb Line: 424

If anyone can shed some light on this subject (namely point out what I'm
doing wrong) it would be greatly appreciated.

A. Nonymous (slightly dazed and confused)

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.