Showing posts with label systemnullreferenceexception. Show all posts
Showing posts with label systemnullreferenceexception. Show all posts

Saturday, March 24, 2012

System.NullReferenceException

How must i declare my variables to have this code work. I get
system.nullreferenceexception every time i click button to add data to
datatable
here below is my code :
Dim wykszt as System.Data.DataTable
Dim zatru as System.Data.DataTable
Private Sub Page_Load(s As Object, e As EventArgs)
if Not IsPostBack Then
make_d_tables()
End if
End Sub
sub make_d_tables()
wykszt = New System.Data.DataTable("wykszt")
wykszt.Columns.Add("od_data", GetType(date))
wykszt.Columns.Add("do_data", GetType(date))
wykszt.Columns.Add("nazwa_szkoly", GetType(String))
wykszt.Columns.Add("nazwa_tytulu", GetType(String))
zatru = New System.Data.DataTable("zatr")
zatru.Columns.Add("od_data", GetType(date))
zatru.Columns.Add("do_data", GetType(date))
zatru.Columns.Add("nazwa_prac", GetType(String))
zatru.Columns.Add("nazwa_stan", GetType(String))
End sub
Sub Button2_Click(sender As Object, e As EventArgs)
row = wykszt.NewRow
row("od_data")=TextBox27.Text + "-01"
row("do_data")=TextBox28.Text + "-01"
row("nazwa_szkoly")=TextBox29.Text
row("nazwa_tytulu")=TextBox30.Text
wykszt.Rows.Add(row)
row = wykszt.NewRow
Mxdatagrid1.datasource=wykszt
Mxdatagrid1.databind
End Sub
Thanks
PatYou have to recreate your tables every time. So take out the if statement
from page_load.
"ven" <venome_@.poczta.onet.pl> wrote in message
news:cif6p8$sf3$1@.news.onet.pl...
> How must i declare my variables to have this code work. I get
> system.nullreferenceexception every time i click button to add data to
> datatable
> here below is my code :
> Dim wykszt as System.Data.DataTable
> Dim zatru as System.Data.DataTable
> Private Sub Page_Load(s As Object, e As EventArgs)
> if Not IsPostBack Then
> make_d_tables()
> End if
> End Sub
> sub make_d_tables()
> wykszt = New System.Data.DataTable("wykszt")
> wykszt.Columns.Add("od_data", GetType(date))
> wykszt.Columns.Add("do_data", GetType(date))
> wykszt.Columns.Add("nazwa_szkoly", GetType(String))
> wykszt.Columns.Add("nazwa_tytulu", GetType(String))
> zatru = New System.Data.DataTable("zatr")
> zatru.Columns.Add("od_data", GetType(date))
> zatru.Columns.Add("do_data", GetType(date))
> zatru.Columns.Add("nazwa_prac", GetType(String))
> zatru.Columns.Add("nazwa_stan", GetType(String))
> End sub
> Sub Button2_Click(sender As Object, e As EventArgs)
> row = wykszt.NewRow
> row("od_data")=TextBox27.Text + "-01"
> row("do_data")=TextBox28.Text + "-01"
> row("nazwa_szkoly")=TextBox29.Text
> row("nazwa_tytulu")=TextBox30.Text
> wykszt.Rows.Add(row)
> row = wykszt.NewRow
> Mxdatagrid1.datasource=wykszt
> Mxdatagrid1.databind
> End Sub
>
> Thanks
> Pat
>
Which line is throwing the exception?
Does the error only happen on postback?
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"ven" <venome_@.poczta.onet.pl> wrote in message
news:cif6p8$sf3$1@.news.onet.pl...
> How must i declare my variables to have this code work. I get
> system.nullreferenceexception every time i click button to add data to
> datatable
> here below is my code :
> Dim wykszt as System.Data.DataTable
> Dim zatru as System.Data.DataTable
> Private Sub Page_Load(s As Object, e As EventArgs)
> if Not IsPostBack Then
> make_d_tables()
> End if
> End Sub
> sub make_d_tables()
> wykszt = New System.Data.DataTable("wykszt")
> wykszt.Columns.Add("od_data", GetType(date))
> wykszt.Columns.Add("do_data", GetType(date))
> wykszt.Columns.Add("nazwa_szkoly", GetType(String))
> wykszt.Columns.Add("nazwa_tytulu", GetType(String))
> zatru = New System.Data.DataTable("zatr")
> zatru.Columns.Add("od_data", GetType(date))
> zatru.Columns.Add("do_data", GetType(date))
> zatru.Columns.Add("nazwa_prac", GetType(String))
> zatru.Columns.Add("nazwa_stan", GetType(String))
> End sub
> Sub Button2_Click(sender As Object, e As EventArgs)
> row = wykszt.NewRow
> row("od_data")=TextBox27.Text + "-01"
> row("do_data")=TextBox28.Text + "-01"
> row("nazwa_szkoly")=TextBox29.Text
> row("nazwa_tytulu")=TextBox30.Text
> wykszt.Rows.Add(row)
> row = wykszt.NewRow
> Mxdatagrid1.datasource=wykszt
> Mxdatagrid1.databind
> End Sub
>
> Thanks
> Pat
>
Uytkownik "Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> napisa w wiadomoci
news:OkGuVzNnEHA.1304@.TK2MSFTNGP09.phx.gbl...
> Which line is throwing the exception?
> Does the error only happen on postback?
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://Steve.Orr.net
>
> "ven" <venome_@.poczta.onet.pl> wrote in message
> news:cif6p8$sf3$1@.news.onet.pl...
>
sorry i left behind that i have Dim row as System.Data.DataRow in my
declarations too
but exception is only when i post back and
on this line :
row = wykszt.NewRow
and a full stack :
Szczegy wyjtku: System.NullReferenceException: Odwoanie do obiektu nie
zostao ustawione na wystpienie obiektu.
Bd rda:
Wiersz 35: Sub Button2_Click(sender As Object, e As EventArgs)
Wiersz 36:
Wiersz 37: row = wykszt.NewRow
Wiersz 38: row("od_data")=TextBox27.Text + "-01"
Wiersz 39: row("do_data")=TextBox28.Text + "-01"
Plik rdowy: c:\inetpub\wwwroot\axell\forma.aspx Wiersz: 37
lad stosu:
[NullReferenceException: Odwoanie do obiektu nie zostao ustawione na
wystpienie obiektu.]
ASP.forma_aspx.Button2_Click(Object sender, EventArgs e) in
c:\inetpub\wwwroot\axell\forma.aspx:37
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
stBackEvent(String eventArgument) +58
System.Web.UI.Page. RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277
sorry for polish language
Thanks
Pat
In that case I agree with Marina.
You need to recreate your table upon each postback.
Right now you aren't doing that, so you can't add a row to a table that
doesn't exist, thus your error.
Remove the If statement in Page_Load.
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net

> sorry i left behind that i have Dim row as System.Data.DataRow in my
> declarations too
> but exception is only when i post back and
> on this line :
> row = wykszt.NewRow
> and a full stack :
> Szczegy wyjtku: System.NullReferenceException: Odwoanie do obiektu nie
> zostao ustawione na wystpienie obiektu.
> Bd rda:
> Wiersz 35: Sub Button2_Click(sender As Object, e As EventArgs)
> Wiersz 36:
> Wiersz 37: row = wykszt.NewRow
> Wiersz 38: row("od_data")=TextBox27.Text + "-01"
> Wiersz 39: row("do_data")=TextBox28.Text + "-01"
>
> Plik rdowy: c:\inetpub\wwwroot\axell\forma.aspx Wiersz: 37
> lad stosu:
> [NullReferenceException: Odwoanie do obiektu nie zostao ustawione na
> wystpienie obiektu.]
> ASP.forma_aspx.Button2_Click(Object sender, EventArgs e) in
> c:\inetpub\wwwroot\axell\forma.aspx:37
> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
> System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.Raise
Po
> stBackEvent(String eventArgument) +58
> System.Web.UI.Page. RaisePostBackEvent(IPostBackEventHandler
> sourceControl, String eventArgument) +18
> System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
> System.Web.UI.Page.ProcessRequestMain() +1277
> sorry for polish language
> Thanks
> Pat
>

System.NullReferenceException

How must i declare my variables to have this code work. I get
system.nullreferenceexception every time i click button to add data to
datatable
here below is my code :

Dim wykszt as System.Data.DataTable
Dim zatru as System.Data.DataTable

Private Sub Page_Load(s As Object, e As EventArgs)

if Not IsPostBack Then
make_d_tables()
End if
End Sub

sub make_d_tables()

wykszt = New System.Data.DataTable("wykszt")
wykszt.Columns.Add("od_data", GetType(date))
wykszt.Columns.Add("do_data", GetType(date))
wykszt.Columns.Add("nazwa_szkoly", GetType(String))
wykszt.Columns.Add("nazwa_tytulu", GetType(String))

zatru = New System.Data.DataTable("zatr")
zatru.Columns.Add("od_data", GetType(date))
zatru.Columns.Add("do_data", GetType(date))
zatru.Columns.Add("nazwa_prac", GetType(String))
zatru.Columns.Add("nazwa_stan", GetType(String))

End sub

Sub Button2_Click(sender As Object, e As EventArgs)

row = wykszt.NewRow
row("od_data")=TextBox27.Text + "-01"
row("do_data")=TextBox28.Text + "-01"
row("nazwa_szkoly")=TextBox29.Text
row("nazwa_tytulu")=TextBox30.Text
wykszt.Rows.Add(row)
row = wykszt.NewRow
Mxdatagrid1.datasource=wykszt
Mxdatagrid1.databind

End Sub

Thanks

PatYou have to recreate your tables every time. So take out the if statement
from page_load.

"ven" <venome_@.poczta.onet.pl> wrote in message
news:cif6p8$sf3$1@.news.onet.pl...
> How must i declare my variables to have this code work. I get
> system.nullreferenceexception every time i click button to add data to
> datatable
> here below is my code :
> Dim wykszt as System.Data.DataTable
> Dim zatru as System.Data.DataTable
> Private Sub Page_Load(s As Object, e As EventArgs)
> if Not IsPostBack Then
> make_d_tables()
> End if
> End Sub
> sub make_d_tables()
> wykszt = New System.Data.DataTable("wykszt")
> wykszt.Columns.Add("od_data", GetType(date))
> wykszt.Columns.Add("do_data", GetType(date))
> wykszt.Columns.Add("nazwa_szkoly", GetType(String))
> wykszt.Columns.Add("nazwa_tytulu", GetType(String))
> zatru = New System.Data.DataTable("zatr")
> zatru.Columns.Add("od_data", GetType(date))
> zatru.Columns.Add("do_data", GetType(date))
> zatru.Columns.Add("nazwa_prac", GetType(String))
> zatru.Columns.Add("nazwa_stan", GetType(String))
> End sub
> Sub Button2_Click(sender As Object, e As EventArgs)
> row = wykszt.NewRow
> row("od_data")=TextBox27.Text + "-01"
> row("do_data")=TextBox28.Text + "-01"
> row("nazwa_szkoly")=TextBox29.Text
> row("nazwa_tytulu")=TextBox30.Text
> wykszt.Rows.Add(row)
> row = wykszt.NewRow
> Mxdatagrid1.datasource=wykszt
> Mxdatagrid1.databind
> End Sub
>
> Thanks
> Pat
Which line is throwing the exception?
Does the error only happen on postback?

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net

"ven" <venome_@.poczta.onet.pl> wrote in message
news:cif6p8$sf3$1@.news.onet.pl...
> How must i declare my variables to have this code work. I get
> system.nullreferenceexception every time i click button to add data to
> datatable
> here below is my code :
> Dim wykszt as System.Data.DataTable
> Dim zatru as System.Data.DataTable
> Private Sub Page_Load(s As Object, e As EventArgs)
> if Not IsPostBack Then
> make_d_tables()
> End if
> End Sub
> sub make_d_tables()
> wykszt = New System.Data.DataTable("wykszt")
> wykszt.Columns.Add("od_data", GetType(date))
> wykszt.Columns.Add("do_data", GetType(date))
> wykszt.Columns.Add("nazwa_szkoly", GetType(String))
> wykszt.Columns.Add("nazwa_tytulu", GetType(String))
> zatru = New System.Data.DataTable("zatr")
> zatru.Columns.Add("od_data", GetType(date))
> zatru.Columns.Add("do_data", GetType(date))
> zatru.Columns.Add("nazwa_prac", GetType(String))
> zatru.Columns.Add("nazwa_stan", GetType(String))
> End sub
> Sub Button2_Click(sender As Object, e As EventArgs)
> row = wykszt.NewRow
> row("od_data")=TextBox27.Text + "-01"
> row("do_data")=TextBox28.Text + "-01"
> row("nazwa_szkoly")=TextBox29.Text
> row("nazwa_tytulu")=TextBox30.Text
> wykszt.Rows.Add(row)
> row = wykszt.NewRow
> Mxdatagrid1.datasource=wykszt
> Mxdatagrid1.databind
> End Sub
>
> Thanks
> Pat
Uytkownik "Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> napisa w wiadomoci
news:OkGuVzNnEHA.1304@.TK2MSFTNGP09.phx.gbl...
> Which line is throwing the exception?
> Does the error only happen on postback?
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://Steve.Orr.net
>
> "ven" <venome_@.poczta.onet.pl> wrote in message
> news:cif6p8$sf3$1@.news.onet.pl...
> > How must i declare my variables to have this code work. I get
> > system.nullreferenceexception every time i click button to add data to
> > datatable
> > here below is my code :
> > Dim wykszt as System.Data.DataTable
> > Dim zatru as System.Data.DataTable
> > Private Sub Page_Load(s As Object, e As EventArgs)
> > if Not IsPostBack Then
> > make_d_tables()
> > End if
> > End Sub
> > sub make_d_tables()
> > wykszt = New System.Data.DataTable("wykszt")
> > wykszt.Columns.Add("od_data", GetType(date))
> > wykszt.Columns.Add("do_data", GetType(date))
> > wykszt.Columns.Add("nazwa_szkoly", GetType(String))
> > wykszt.Columns.Add("nazwa_tytulu", GetType(String))
> > zatru = New System.Data.DataTable("zatr")
> > zatru.Columns.Add("od_data", GetType(date))
> > zatru.Columns.Add("do_data", GetType(date))
> > zatru.Columns.Add("nazwa_prac", GetType(String))
> > zatru.Columns.Add("nazwa_stan", GetType(String))
> > End sub
> > Sub Button2_Click(sender As Object, e As EventArgs)
> > row = wykszt.NewRow
> > row("od_data")=TextBox27.Text + "-01"
> > row("do_data")=TextBox28.Text + "-01"
> > row("nazwa_szkoly")=TextBox29.Text
> > row("nazwa_tytulu")=TextBox30.Text
> > wykszt.Rows.Add(row)
> > row = wykszt.NewRow
> > Mxdatagrid1.datasource=wykszt
> > Mxdatagrid1.databind
> > End Sub
> > Thanks
> > Pat

sorry i left behind that i have Dim row as System.Data.DataRow in my
declarations too
but exception is only when i post back and
on this line :
row = wykszt.NewRow

and a full stack :

Szczegy wyjtku: System.NullReferenceException: Odwoanie do obiektu nie
zostao ustawione na wystpienie obiektu.

Bd rda:

Wiersz 35: Sub Button2_Click(sender As Object, e As EventArgs)
Wiersz 36:
Wiersz 37: row = wykszt.NewRow
Wiersz 38: row("od_data")=TextBox27.Text + "-01"
Wiersz 39: row("do_data")=TextBox28.Text + "-01"

Plik rdowy: c:\inetpub\wwwroot\axell\forma.aspx Wiersz: 37

lad stosu:

[NullReferenceException: Odwoanie do obiektu nie zostao ustawione na
wystpienie obiektu.]
ASP.forma_aspx.Button2_Click(Object sender, EventArgs e) in
c:\inetpub\wwwroot\axell\forma.aspx:37
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
stBackEvent(String eventArgument) +58
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277

sorry for polish language

Thanks

Pat
In that case I agree with Marina.
You need to recreate your table upon each postback.
Right now you aren't doing that, so you can't add a row to a table that
doesn't exist, thus your error.
Remove the If statement in Page_Load.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net

> sorry i left behind that i have Dim row as System.Data.DataRow in my
> declarations too
> but exception is only when i post back and
> on this line :
> row = wykszt.NewRow
> and a full stack :
> Szczegy wyjtku: System.NullReferenceException: Odwoanie do obiektu nie
> zostao ustawione na wystpienie obiektu.
> Bd rda:
> Wiersz 35: Sub Button2_Click(sender As Object, e As EventArgs)
> Wiersz 36:
> Wiersz 37: row = wykszt.NewRow
> Wiersz 38: row("od_data")=TextBox27.Text + "-01"
> Wiersz 39: row("do_data")=TextBox28.Text + "-01"
>
> Plik rdowy: c:\inetpub\wwwroot\axell\forma.aspx Wiersz: 37
> lad stosu:
> [NullReferenceException: Odwoanie do obiektu nie zostao ustawione na
> wystpienie obiektu.]
> ASP.forma_aspx.Button2_Click(Object sender, EventArgs e) in
> c:\inetpub\wwwroot\axell\forma.aspx:37
> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
> System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
> stBackEvent(String eventArgument) +58
> System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
> sourceControl, String eventArgument) +18
> System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
> System.Web.UI.Page.ProcessRequestMain() +1277
> sorry for polish language
> Thanks
> Pat

System.NullReferenceException

I hope this is the right forum section. I am a getting started. Please take a look at this I can't seem to get this data connection to work.

Sub Page_Load()
Teamlist.Datasource = getteams
teamlist.databind()
End Sub

Function GetTeams() As System.Data.IDataReader
Dim connectionString As String = _
ConfigurationSettings.AppSettings("connectionstring")
Dim dbConnection = ConfigurationSettings.AppSettings("connectionstring")

Dim queryString As String = "SELECT [Teams].[TeamID], [Teams].[TeamName], [Teams].[Notes] FROM [Teams]"
Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

dbConnection.Open
Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

Return dataReader
End Function

Now I get this:
Exception Details: System.NullReferenceException: Object variable or With block variable not set.

Source Error:

Line 21: dbCommand.Connection = dbConnection
Line 22:
Line 23: dbConnection.Open
Line 24: Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
Line 25:

Here is the contents of my web.config

<?xml version="1.0" encoding="UTF-8" ?
<configuration
<!--

The <appSettings> section is used to configure application-specific configuration
settings. These can be fetched from within apps by calling the
"ConfigurationSettings.AppSettings(key)" method:

<appSettings>
<add key="connectionstring"
value="Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4;
Data Source=C:\begaspnet11\wroxunited\database\wroxunited.mdb"/>
</appSettings
--
<system.web
<!--

The <sessionState" section is used to configure session state for the application.
It supports four modes: "Off", "InProc", "StateServer", and "SqlServer". The
later two modes enable session state to be stored off the web server machine -
allowing failure redundancy and web farm session state scenarios.

<sessionState mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;trusted_connection=true"
cookieless="false"
timeout="20" /
--
<!--

The <customErrors> section enables configuration of what to do if/when an
unhandled error occurs during the execution of a request. Specifically, it
enables developers to configure html error pages to be displayed in place of
a error stack trace:

<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm"/>
<error statusCode="404" redirect="FileNotFound.htm"/>
<customErrors
--
<!--

The <authentication> section enables configuration of the security authentication
mode used by ASP.NET to identify an incoming user. It supports a "mode"
attribute with four valid values: "Windows", "Forms", "Passport" and "None":

The <forms> section is a sub-section of the <authentication> section,
and supports configuring the authentication values used when Forms
authentication is enabled above:

<authentication mode="Windows"
<forms name=".ASPXAUTH"
loginUrl="login.aspx"
protection="Validation"
timeout="999999" /
</authentication
--
<!--

The <authorization> section enables developers/administrators to configure
whether a user or role has access to a particular page or resource. This is
accomplished by adding "<allow>" and "<deny>" sub-tags beneath the <authorization>
section - specifically detailing the users/roles allowed or denied access.

Note: The "?" character indicates "anonymous" users (ie: non authenticated users).
The "*" character indicates "all" users.

<authorization>
<allow users="joeuser" />
<allow roles="Admins" />
<deny users="*" />
</authorization
--
</system.web
</configuration>Hi,
Which line throw an error?
One problem I can see in your code is connection scope. DataReader can not be used if associated connection is closed. In your case connection (attached to command object) exists in scope of GetTeams scope and you are using DataReader out of this scope. It is wrong.
Line 23
dbconnection.open
Change this:


Dim dbConnection = ConfigurationSettings.AppSettings("connectionstring")

to:

Dim dbConnection as New SqlConnection()
dbConnection.ConnectionString = ConfigurationSettings.AppSettings("connectionstring")

dbConnection should be declared in the same scope where you are using associated datareader (see my previous reply)
1. Appreciate you working with me.

2. I'm using a Access mdb for this. How do that change this:

Dim dbConnection as New SqlConnection()

dbConnection.ConnectionString = ConfigurationSettings.AppSettings("connectionstring")

Thanks!
Rich
Sorry, I did not realize it is OleDb. Use this instead:


Dim dbConnection as New OleDbConnection()
dbConnection.ConnectionString = ConfigurationSettings.AppSettings("connectionstring")

Thanks but I got the same error.

The ConnectionString property has not been initialized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The ConnectionString property has not been initialized.

Source Error:

Line 25: dbCommand.Connection = dbConnection
Line 26:
Line 27: dbConnection.Open
Line 28: Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
Line 29:

Source File: C:\begasnet11\wroxunited\teams.aspx Line: 27

Stack Trace:

[InvalidOperationException: The ConnectionString property has not been initialized.]
System.Data.OleDb.OleDbConnection.Open() +203
ASP.teams_aspx.GetTeams() in C:\begasnet11\wroxunited\teams.aspx:27
ASP.teams_aspx.Page_Load() in C:\begasnet11\wroxunited\teams.aspx:9
System.Web.Util.ArglessEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +10
System.Web.UI.Control.OnLoad(EventArgs e) +55
System.Web.UI.Control.LoadRecursive() +27
System.Web.UI.Page.ProcessRequestMain() +731

------------------------

Dim dbConnection as New OleDbConnection(ConfigurationSettings.AppSettings("connectionstring"))
Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand("SELECT [Teams].[TeamID], [Teams].[TeamName], [Teams].[Notes] FROM [Teams]", dbConnection)
Constructors are faster than instantiating and then initializing (admittedly you won't be noticing the speed gain, but still, it's good to have performance in mind at all times).
Still nothing. I've tried this on 2 diffrent computers. Grasping at straws.

Same error.

Thanks!
Rich
Was this statement (dbConnection.ConnectionString = ConfigurationSettings.AppSettings("connectionstring") ) executed?
If it was, check dbConnection.ConnectionString value in debugger. May be Config file entry was not read correctly.
I set debug to true and this is what I got in addition to the same error

[InvalidOperationException: The ConnectionString property has not been initialized.]
System.Data.OleDb.OleDbConnection.Open() +203
ASP.teams_aspx.GetTeams() in C:\begasnet11\wroxunited\teams.aspx:26
ASP.teams_aspx.Page_Load() in C:\begasnet11\wroxunited\teams.aspx:10
System.Web.Util.ArglessEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +10
System.Web.UI.Control.OnLoad(EventArgs e) +55
System.Web.UI.Control.LoadRecursive() +27
System.Web.UI.Page.ProcessRequestMain() +731
Man I feel so dumb. OK here it is. The <appsettings> in the webconfig file was commented out. I removed the comment tags and bang.

Thanks everyone!!
Does it matter if this is in a folder or a virtual directory? Does the web config file need a virtual directory to work in like a global asa?

System.NullReferenceException

Hi,

Can somebody tell me how I get this error?

here is a snippet of the code:

<span class="Normal">
<asp:Label runat="Server" Text='<%# DataBinder.Eval(Container.DataItem,"CreatedByUser") %>' ID="Label1"/>
</span>
<% if (Context.User.Identity.Name == Label1.Text) { %>
<asp:HyperLink id="editLink" ImageUrl="~/images/edit.gif" NavigateUrl='<%# "~/DesktopModules/EditAnnouncements.aspx?ItemID=" + DataBinder.Eval(Container.DataItem,"ItemID") + "&mid=" + ModuleId %>' Visible="<%# IsEditable %>" runat="server" />
<% } %>
<span class="ItemTitle">
<%# DataBinder.Eval(Container.DataItem,"Title") %>
</span
and here is the compiler error:

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

Line 9: <asp:Label runat="Server" Text='<%# DataBinder.Eval(Container.DataItem,"CreatedByUser") %>' ID="Label1"/>
Line 10: </span>
Line 11: [RED MARKED]<% if (Context.User.Identity.Name == Label1.Text) { %>[\RED MARKED]
Line 12: <asp:HyperLink id="editLink" ImageUrl="~/images/edit.gif" NavigateUrl='<%# "~/DesktopModules/EditAnnouncements.aspx?ItemID=" + DataBinder.Eval(Container.DataItem,"ItemID") + "&mid=" + ModuleId %>' Visible="<%# IsEditable %>" runat="server" />
Line 13: <% } %
Hope you can help me

regards

delleNullReferenceException's usually occur (in my experience anyway) when you have programmed an event to occur and presumed a variable/data source will be available and (for one of many possible reasons) it isn't.

I see you are using a databound control - have you told the control where to get it's data from? have called the DataBind event of the control?

Could you give us a bit more code?
Which line in the code is it telling you is causing this error?
You have to check Context.User for null before use
Hi,
Now I'm checking the value "Context.User.Identity.Name" for "null".

This was one problem I guess, because now I can build the project without an error,
but when I log in I still become an error.
I replaced my variables with constants to see if the function would work, and yes it is working.
The problem is that the value of Label1.Text cannot be compared with "Context.User.Identity.Name" for some reason.

Here is the new code:
<span class="Normal">
<%# DataBinder.Eval(Container.DataItem,"CreatedByUser") %>
<asp:Label runat="Server" Text='<%# DataBinder.Eval(Container.DataItem,"CreatedByUser") %>' ID="Label1"/>
</span>
<% if (Context.User.Identity.Name != "") { %>
<% if (Context.User.Identity.Name == Label1.Text) { %>
<asp:HyperLink id="editLink" ImageUrl="~/images/edit.gif" NavigateUrl='<%# "~/DesktopModules/EditAnnouncements.aspx?ItemID=" + DataBinder.Eval(Container.DataItem,"ItemID") + "&mid=" + ModuleId %>' Visible="<%# IsEditable %>" runat="server" />
<% } %>
<% } %>
<span class="ItemTitle">
<%# DataBinder.Eval(Container.DataItem,"Title") %>
</span
The error the compiler gives me is still the same in line 12:

Line 10: </span>
Line 11: <% if (Context.User.Identity.Name != "") { %>
Line 12: <% if (Context.User.Identity.Name == Convert.ToString(Label1.Text)) { %>
Line 13: <asp:HyperLink id="editLink" ImageUrl="~/images/edit.gif" NavigateUrl='<%# "~/DesktopModules/EditAnnouncements.aspx?ItemID=" + DataBinder.Eval(Container.DataItem,"ItemID") + "&mid=" + ModuleId %>' Visible="<%# IsEditable %>" runat="server" />
Line 14: <% } %
Suggestions would be very appreciated.
thx.

System.NullReferenceException

I'm learning C# and I seem to be making all sorts of mistakes. Could anyone help me troubleshoot my error? I tried to document the logic as best as I could.

// PassID: Call GetEmail Stored Procedure: Grab Emails from every contact that is equal to the value of x.
// x represents the value of each checkbox the user checked on SendEmail.aspx

private void PassID(string x)
{
// Set connection string to database
//string ConnectionString = System.Configuration.ConfigurationManager.AppSettings["FasR6ConnectionString"].ToString();

string ConnectionString = "Data Source=NOTEBOOK;Initial Catalog=FasR6;Integrated Security=True";


// Create new connection and pass in the value of the connection string as a parameter
// Use GetEmail to call the stored procedure which will return the emails to send out.
SqlConnection ConnectToDatabase = new SqlConnection(ConnectionString);
string GetEmail = "spGetEmail";

//Create SqlCommand object and pass in the stored procedure and connection as parameters
// Define the command type as a stored procedure
SqlCommand objCommand = new SqlCommand(GetEmail, ConnectToDatabase);
objCommand.CommandType = CommandType.StoredProcedure;

// Define a SqlParamenter of type Int to hold the value of SinID.
SqlParameter objParameter = new SqlParameter("@dotnet.itags.org.ID", SqlDbType.Int);
objCommand.Parameters.Add(objParameter);
objParameter.Direction = ParameterDirection.Input;
objParameter.Value = x; // x is the value of each checkbox that is checked

//create a new data adapter and pass in sql command via my stored procedure.
SqlDataAdapter objAdapter = new SqlDataAdapter(objCommand);
DataSet objDataSet = new DataSet("dtEmail"); //Create a data table named dtEmail to hold what the stored procedure returns.
objAdapter.Fill(objDataSet); //Fill the dataset


if (objDataSet.Tables["dtEmail"].Rows.Count != 0) // <=============== System.NullReferenceException was unhandled by user code (Details Below)

{

ContactIdentifier = null;
string tempString = objDataSet.Tables["dtEmail"].Rows[0]["ContractorID"].ToString();
string tempString2 = Convert.ToString(ContactIdentifiers.Find(tempString));


if (tempString == null)
{
ContactIdentifier = ContactIdentifiers.Add();
ContactIdentifier.EmailAddress = (objDataSet.Tables["dtEmail"].Rows[0]["Email1"].ToString());
}
}

*******************************************************************************************************************************

//System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_Web_tfcl-8tl"
StackTrace:
at Partnering_SendEmail.PassID(String x) in ****************************:line 74
at Partnering_SendEmail.btnSubmit_Click(Object sender, EventArgse) in ******************************SendEmail.aspx.cs:line 33
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

The below line is wrong:

DataSet objDataSet = new DataSet("dtEmail"); //Create a data table named dtEmail to hold what the stored procedure returns.

It doesn't create a data table called "dtEmail" but it creates a dataset named "dtEmail". So you will not have a data table in the dataset with this name. If you want to name the datatable inside a dataset use:

objAdapter.Fill(objDataSet, "dtEmail"); //Fill the dataset


woohooo it works!!!!!!!

Thanks for all of the help!

System.NullReferenceException

Hello people,

this is my first time ever to post a question on this asp.net forum, so I hope this would be a wonderful experience from here on.

Here is my problem, I get " System.NullReferenceException " this error at not a compile time, but atruntime time.

here is my code

protectedvoid dl_UpdateCommand(objectsource,DataListCommandEventArgs e)

{

// Read inthe ProductID from the DataKeys collection

intFileID =Convert.ToInt32(dl.DataKeys[e.Item.ItemIndex]);

// Readin the product name and price values

TextBoxtxtEditFileName = (TextBox)e.Item.FindControl("FileName");

TextBoxtxtEditDescription = (TextBox)e.Item.FindControl("Description");

stringFileNameValue =null;//"null" wil not work.Error Occurs here

if(txtEditFileName.Text.Trim().Length > 0)

FileNameValue =txtEditFileName.Text.Trim();

stringDescriptionValue =null;Error Occurs here

if(txtEditDescription.Text.Trim().Length > 0)

DescriptionValue =txtEditDescription.Text.Trim();

#region- "changed Updatemechanism"

// Call theUpdate method to Update FileName, Description...

SqlConnectionmyConnection =newSqlConnection(ConfigurationManager.ConnectionStrings["ARCCAOHelpConnectionString"].ConnectionString);

//stringsqlString = "SELECT * FROM ARCCA_FileUpload1 WHERE FileID=" + FileID;

stringsqlString ="SELECT * FROMARCCA_FileUpload1";

SqlDataAdapterdataAdapter =newSqlDataAdapter(sqlString,myConnection);

DataSetdataSet =newDataSet();

DataRowdataRow;

// Createcommand builder. This line automatically generates the update commands for you,so you don't

// have toprovide or create your own.

SqlCommandBuildersqlCmdBuild =newSqlCommandBuilder(dataAdapter);

// Set theMissingSchemaAction property to AddWithKey because Fill will not cause primary

// key &unique key information to be retrieved unless AddWithKey is specified.

dataAdapter.MissingSchemaAction =MissingSchemaAction.AddWithKey;

dataAdapter.Fill(dataSet,"ARCCA_FileUpload1");

dataRow = dataSet.Tables["ARCCA_FileUpload1"].NewRow();

dataRow["FileID"]=FileID;

dataRow["FileName"]=FileNameValue;

dataRow["Description"]=DescriptionValue;

dataSet.Tables["ARCCA_FileUpload1"].Rows.Add(dataRow);

// Revert theDataList back to its pre-editing state

dl.EditItemIndex = -1;

dl.DataBind();

}

now, how to fix it?

Set it to string.empty


SonuKapoor:

Set it to string.empty

i wonder why it shouldn't work ... setting a string to null works just fine with me ...


Trickass: You are right it should work with null as well.

eddieiam: Are you sure that this is line causing the error?


Hi Sonu,

the actual line thats causing the error isif (txtEditFileName.Text.Trim().Length > 0) . On this line, I get error: System.NullReferenceException: Object reference not set to an instance of an object


You have to make sure that the row contains a textbox with the id "FileName". Can you show me the HTML declaration of your GridView?



Anytime that you use FindControl, you should ALWAYS do a null check before using the control, as that is what you get if it doesn't find the control.

FindControl should always be used like this:
Control controlRef = e.Item.FindControl("FileName");
if ( controlRef != null )
{
TextBox txtEditFileName = (TextBox)controlRef;

// Remainder of processing for this TextBox...
}

Could be that "FileName" is not the correct ClientID for this control because of spelling, case-sensitivity, or that the control is inside of a container which changes the ClientID by adding on the container ClientID (masterPageID + "_" + controlID).

NC...


NC01: I have masterPage, but i am not assigning masterPageID to the control at the aspx page. Also, I've tried using the Control to FindControl it now gives me FileNameValue does not exist error


The easiest way to solve that is to bring the page up in your browser and do a View Source on it then find the control to see what the ending ClientID is.

NC...


Hold it! If this control is in a DataList, DataGrid, or GridView, etc, this should work, and could give you an idea of the problem.

protected void dl_UpdateCommand(object source, DataListCommandEventArgs e)
{
// Iterate through all controls on the row:
for (int i=0; i<e.Item.Controls.Count; i++)
{
Control controlRef = e.Item.Controls[i];
string controlId = string.Empty;

if ( controlRef is LinkButton )
controlId = ((LinkButton)controlRef).ClientID;
else if ( controlRef is Label )
controlId = ((Label)controlRef).ClientID;
else if ( controlRef is TextBox )
controlId = ((TextBox)controlRef).ClientID;
// else any other controls here
}
}

NC...


Hey uh, you good!. thanks for your effort in helping me. really do appriciate. but still i get the same error buddy. By the way, its a DataList that I am binding to. And

using the Edit template to edit. let me also post the aspx page for ref which will be down below after the cs code.

thanks.. again..

protected void dl_UpdateCommand(object source, DataListCommandEventArgs e)
{
//Iterate through all controls on the row:
// Iterate through all controls on the row:
for (int i = 0; i < e.Item.Controls.Count; i++)
{
Control controlRef = e.Item.Controls[i];
string controlId = string.Empty;

if (controlRef is LinkButton)
controlId = ((LinkButton)controlRef).ClientID;
else if (controlRef is Label)
controlId = ((Label)controlRef).ClientID;
else if (controlRef is TextBox)
controlId = ((TextBox)controlRef).ClientID;
// else any other controls here
}

// Read in the ProductID from the DataKeys collection
int FileID = Convert.ToInt32(dl.DataKeys[e.Item.ItemIndex]);

// Read in the product name and price values
TextBox txtEditFileName = (TextBox)e.Item.FindControl("FileName");
TextBox txtEditDescription = (TextBox)e.Item.FindControl("Description");
string FileNameValue = null; // "null" wil not work.
if (txtEditFileName.Text.Trim().Length > 0)
FileNameValue = txtEditFileName.Text.Trim();

string DescriptionValue = null;
if (txtEditDescription.Text.Trim().Length > 0)
DescriptionValue = txtEditDescription.Text.Trim();

#region- "changed Update mechanism"
// Call the Update method to Update FileName, Description...
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ARCCAOHelpConnectionString"].ConnectionString);
//string sqlString = "SELECT * FROM ARCCA_FileUpload1 WHERE FileID=" + FileID;
string sqlString = "SELECT * FROM ARCCA_FileUpload1";
SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlString,myConnection);
DataSet dataSet = new DataSet();
DataRow dataRow;

// Create command builder. This line automatically generates the update commands for you, so you don't
// have to provide or create your own.
SqlCommandBuilder sqlCmdBuild = new SqlCommandBuilder(dataAdapter);

// Set the MissingSchemaAction property to AddWithKey because Fill will not cause primary
// key & unique key information to be retrieved unless AddWithKey is specified.
dataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

dataAdapter.Fill(dataSet,"ARCCA_FileUpload1");
dataRow = dataSet.Tables["ARCCA_FileUpload1"].NewRow();
dataRow["FileID"]=FileID;
dataRow["FileName"]= FileNameValue;
dataRow["Description"]= DescriptionValue;

dataSet.Tables["ARCCA_FileUpload1"].Rows.Add(dataRow);

// Revert the DataList back to its pre-editing state
dl.EditItemIndex = -1;
dl.DataBind();
#endregion

#region- "obselete Update mechanism"
//// Call the Update method to Update FileName, Description...
//using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ARCCAOHelpConnectionString"].ConnectionString))
//{
// myConnection.Open();
// string conString = "UPDATE ARCCA_FileUpload1 SET FileName ='txtEditFileName', Description ='txtEditDescription' WHERE FileID=" + FileID;
// using (SqlCommand cmd = new SqlCommand(conString, myConnection))
// {
// cmd.Connection.Open();
// SqlDataAdapter da = new SqlDataAdapter();
// da.UpdateCommand = cmd;
// DataSet dataSet = new DataSet();
// da.Fill(dataSet);
// }
//}

//// Revert the DataList back to its pre-editing state
//dl.EditItemIndex = -1;
//dl.DataBind();
#endregion
}

protected void dl_CancelCommand(object source, DataListCommandEventArgs e)
{
// Set the DataList's EditItemIndex property to -1
dl.EditItemIndex = -1;

// Rebind the data to the DataList
dl.DataBind();
}

<%@. Page Language="C#" MasterPageFile="~/ARCCAAccess.master" AutoEventWireup="true" CodeFile="TestPage.aspx.cs" Inherits="TestPage" Title="Untitled Page" %
<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:DataList runat="server" ID="dl" DataKeyField="FileID"
OnItemCommand="dl_ItemCommand"
OnEditCommand="dl_EditCommand" OnDeleteCommand="dl_DeleteCommand"
OnUpdateCommand="dl_UpdateCommand" OnCancelCommand="dl_CancelCommand" >

<ItemTemplate>
<cc1:HoverMenuExtender ID="HoverMenuExtender1" runat="server" TargetControlID="HypLnkFileName"
PopupControlID="Panel1" PopupPosition="Right" OffsetX="6" PopDelay="25" HoverCssClass="popupHover">
</cc1:HoverMenuExtender>
<asp:Panel ID="Panel1" runat="server" BackColor="White" BorderColor="Blue" BorderStyle="Solid"
BorderWidth="1px" CssClass="popupMenu" Width="350px" >
<asp:Label ID="lblDescription" ForeColor="black" Font-Size="14px"
runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Description") %>'></asp:Label>
<asp:LinkButton ID="btnEdit" runat="server" CausesValidation="true" CommandName="Edit">Edit</asp:LinkButton>
<asp:LinkButton ID="btnDelete" runat="server" CommandName="Delete">Delete</asp:LinkButton>
</asp:Panel>
<asp:LinkButton ID="HypLnkFileName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "FileName") %>'></asp:LinkButton>
</ItemTemplate>

<EditItemTemplate>
<asp:Panel ID="Panel2" runat="server" BackColor="White" BorderColor="Blue" BorderStyle="Solid"
BorderWidth="1px" CssClass="popupMenu" Width="500px">
FileName :<asp:TextBox ID="txtEditFileName" Text='<%# DataBinder.Eval(Container.DataItem, "FileName") %>'
runat="server" ></asp:TextBox>
Description :<asp:TextBox ID="txtEditDescription" Text='<%# DataBinder.Eval(Container.DataItem, "Description") %>'
runat="server" Width="175px"></asp:TextBox>
<asp:LinkButton ID="btnUpdate" Text="Update" ForeColor="Red" CommandName="Update"
runat="server"></asp:LinkButton>
<asp:LinkButton ID="btnCancel" Text="Cancel" ForeColor="Red" CommandName="Cancel"
runat="server"></asp:LinkButton>
</asp:Panel>
</EditItemTemplate>

</asp:DataList>
</asp:Content


Try this:

Panel p = (Panel)e.Item.FindControl("Panel2");
TextBox txtEditDescription = (TextBox)p.FindControl("Description");


Try what SonuKapoor posted because txtEditFileName and txtEditDescription are definitely inside of the Panel2 container, so the ClientID would probably be dl_Panel2_txtEditFileName. So even the code that I gave you to test with wouldn't pick them up I don't think. It would only pickup HoverMenuExtender1, Panel1, HypLnkFileName, and Panel2 (I believe).

This should work for the FileName TextBox:
Panel p = (Panel)e.Item.FindControl("Panel2");
TextBox txtEditFileName = (TextBox)p.FindControl("txtEditFileName");

NC...


I don't think that you would need the ClientID anyways.


I was thinking if I need to place the contentPlaceHolder Id with FindControl to make it work. since I had a similar problem while adding export to excel some documents from web.

System.NullReferenceException

Hi

I try to use this piece of code...


Dim CatID As Integer
CatID = (Request.QueryString("ID"))
CatID = 1
myProductsByCategory.Text = (GetProductsByCategory(CatID))

inside my Private Sub Page_Load but I get a System.NullReferenceException error from this.

What am I missing here?

Regards

MMy guess would be that the Querystring "ID" doesnt exist and you are getting a NULL exception when VB is converting it to an integer.
I hit Post too soon.. you might want to try to comment out the line that is assigning the value from the Querystring, since you are hardcoding it anyway (to 1).. see if thats the issue.
Hi

I comment out the querystring part, but that didn't help...

Regards

M
By the way... the function I try to call looks like this..

Function GetProductsByCategory(ByVal intID As Integer)

Dim connStr As String
connStr = ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_connStr")

Dim sb As StringBuilder = New StringBuilder
Dim sbOutput As String

Dim MyConnection As SqlConnection
Dim MyCommand As SqlCommand
Dim MyDataReader As SqlDataReader

MyConnection = New SqlConnection(connStr)
Try
MyConnection.Open()
MyCommand = New SqlCommand("dbo.p_ShowProductsByCategories", MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure
MyCommand.Parameters.Add("@.ID", SqlDbType.Int, 4).Value = intID
MyDataReader = MyCommand.ExecuteReader()

sb.Append("<table width=""123"" border=""0"" cellpadding=""0"" cellspacing=""0"">")

While MyDataReader.Read
sb.Append("<tr>")
sb.Append("<td class=""menuitem"" onmouseover=""this.bgColor='#EEEEEE'"" onmouseout=""this.bgColor='#FDFDFD'"" style=""HEIGHT: 16px""> <a ref=""productdetail.aspx?ID=""" & (MyDataReader("ID")) & """>" & (MyDataReader("Description")) & "</a></td>" & vbCrLf)
sb.Append("</tr>")
End While

sb.Append("</table>")

sbOutput = sb.ToString()

MyDataReader.Close()
MyConnection.Close()

Catch ex As Exception
myErrorCode.Visible = True
myErrorCode.Text = (" ! An error occured <br> while accesing<br> products")
'Response.Write(ex.Message.ToString)
End Try
GetProductsByCategory = sbOutput
End Function

Regards

M
Ok.. is the runtime error not giving you the line number of the error? Are you sure the error is happening in those original 4 lines of code posted?
Try setting a breakpoint on the offending line and stepping through the GetProductsByCategory method to see where the problem lies.

(If you don't have Visual Studio you can use the CLR debugger in the .net framework SDK. You'll find it at

C:\Program Files\Microsoft.NET\FrameworkSDK\GuiDebug\DbgCLR.exe

You'll need to attach it to the aspnet_wp.exe process first. Choose "Debug Processes..." on the "Tools" menu, select aspnet_wp.exe and click "Attach".)
You are right, sorry! The line where the error is ...

myProductsByCategory.Text = (GetProductsByCategory(1))

Regards

M
Ok.. best case, your myProductsByCategory.Text is the problem.. worse case its a problem in the function, which is most likely the problem :)


connStr = ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_connStr")

Are yousure that you have this entry in your web.config file?
Yes I have, I use that part in the sub page_load so I know thats working.

Regards

M
Time to step through your code and see whats up then :)
Hmmm... I found the problem, I have forgotten to add the runat=server to the label holding the result.

Regards

M

System.NullReferenceException on trace.axd

Hi all
I posted this in the MVP ASP.NET Forum but I can't seem to make my posts sho
w up in the list.
Paulo Morgado
Portugal
I'm getting the error below when truing to view the details in trace.axd.
What can this be?
Paulo Morgado
Server Error in '/worklog' Application.
----
--
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the cur
rent web request. Please review the stack trace for more information about t
he error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set t
o an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an o
bject.]
System.Web.Handlers.TraceHandler.CreateControlTable(DataTable datatable) +19
74
System.Web.Handlers.TraceHandler.ShowDetails(DataSet data) +198
System.Web.Handlers.TraceHandler.System.Web.IHttpHandler.ProcessRequest(Http
Context context) +559
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionSte
p.Execute() +179
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&complete
dSynchronously) +87Hi Paulo,
I have checked the stack trace, this error can be related with
CreateControlTable.
We can also find the following information for CreateControlTable:
private static System.Web.UI.WebControls.Table
CreateControlTable(System.Data.DataTable datatable)
It seems that the error message is related with the controls on your web
application.
Paulo, according to the stack trace, it is really hard for me to find out
more information. Can you help to collect some additional information?
Thanks for your effort and time.
1. Please share the sample code which will cause the NullReferenceException
on your side. I will perform more research based on the code.
2. Please let me know the .NET Framework version you installed on the
machine, 1.0 or 1.1.
We can check this information in the Add or Remove Programs in the
Control Panel.
I look forward to hearing from you soon. Have a nice day!
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Hi Paulo,
Thanks for your sharing.
To make the application run on my side, I performed the following
modifications:
1. Change the connection string in web.config:
<add key="ConnectionString" value="packet size=4096;user
id=sa;password=11111111;data source=localhost;persist security
info=False;initial catalog=Northwind" />
I also created the table "ESIAHD_TicketHistoricoVista" in the "Northwind"
database with the following columns:
HistoricoID
Date
CaseID
2. Simplified the Reperter component like following:
<asp:repeater id="ListHistoryTicket" runat="server">
<ItemTemplate>
<tr class="thf2c">
<td class="thf2c"> <%# DataBinder.Eval(Container.DataItem, "Data",
"{0:yyyy-MM-dd HH:mm:ss}") %> </td>
</tr>
</ItemTemplate>
<HeaderTemplate>
<table class='tblsize' border="0" cellpadding='0' cellspacing='1'
width="100%">
<thead>
<tr>
<th class="thf">
Data</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<FooterTemplate>
<tfoot>
</tfoot>
</tbody></table>
</FooterTemplate>
</asp:repeater>
3. Change the code like following:
comando.CommandText = @."select HistoricoID, Data from
dbo.ESIAHD_TicketHistoricoVista where CaseID = @.CaseID";
Run the application and checked with trace.axd. Everything works fine.
Paulo, I also attached the modified sample in this message and will also
send it to you via email. Can you try to test with the modified sample
again? If there is still a problem, please try the modified sample on
another web site or on another machine. Please let me know the result.
Thanks for your effort and time!
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Working on a Windows 2000 5.00.2195 SP2 and .NET Framework 1.1
The application is working fine. I'm having trouble only with the trace.
web.config:
<?xml version="1.0" encoding="utf-8" ?><configuration><system.web><compilati
on defaultLanguage="c#" debug="true" /><customErrors mode="RemoteOnly" defau
ltRedirect="Erro.htm" /><authentication mode="None" /><authorization><allow
users="*" /><!-- Allow all
users --></authorization><trace enabled="true" requestLimit="10" pageOutput=
"false" traceMode="SortByTime" localOnly="true" /><sessionState mode="InProc
" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data so
urce=127.0.0.1;Trusted_Conn
ection=yes"
cookieless="false" timeout="20" /><globalization requestEncoding="utf-8" res
ponseEncoding="utf-8" /></system.web><appSettings><add key="ConnectionString
" value="whatever" /></appSettings></configuration>
Xref: kermit microsoft.public.dotnet.framework.aspnet:264481
Hi Paulo,
Yes, generally speaking "Trace" is seperate from application code. However,
some times trace will also report errors when there are some issues with
the configuration or code.
According to your last information, the error does not appear on the
Windows XP machine, I suggest that we perform the following steps to
further narrow down this issue besides running the sample application:
1. Create one empty web application on the production or test server.
2. Enable Trace to the "@.Page" directive.
3. Now, please check if there is any error message when running the web
application.
4. If everything is OK, add code like following to Page_Load:
Trace.Write("test");
5. Run the web application again and check if there is any error message.
If there is any new finding, feel free to let me know. Thanks!
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Hi Paulo,
You means even a simple project will also suffer the problem on the win2k3
server ? If so, I suspect that whether the ASP.NET is correctdly installed
or is corrupted on the server machine. Would you please try reinstalling
the ASP.NET via the
"aspnet_regiis -i" in command in the vs.net commandline prompt?
For more detailed info on the aspnet_regiis tool, you may view the
following reference in MSDN:
#ASP.NET IIS Registration Tool (Aspnet_regiis.exe)
http://msdn.microsoft.com/library/e...netiisregistrat
iontoolaspnet_regiisexe.asp?frame=true
If you have any new findings, please feel free to post here. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Hi Paulo,
You mean after run the
aspnet_regiis -i in the commandline, all the aspx page on your machine
can't be requested(return 404 error)? If so, it doesn seems so strange.
Have you installed both .net framework1.0 and 1.1 on this machine? If so,
which version's regiis tool have you used?
the one under
F:\WINDOWS\Microsoft.NET\Framework\v1.0.3705
is for 1.0
and the one under
F:\WINDOWS\Microsoft.NET\Framework\v1.1.4322
is for 1.1
I think you can directly go to the
F:\WINDOWS\Microsoft.NET\Framework\v1.1.4322 folder and
run
aspnet_regiis -u to remove the asp.net and
then run
aspnet_regiis -i again to install and see whether it helps.
Also, since the 404 error is generally returned by IIS, I recommend that
you have a check in the IIS log to see whether it can provide any clues.
Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Hi Paulo,
If you select "clear current trace", and then add some information to the
trace log and thow the trace details again, Can this fixed the problem?
Luke
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Thursday, March 22, 2012

System.NullReferenceException on trace.axd

Hi Paulo,

I have checked the stack trace, this error can be related with
CreateControlTable.

We can also find the following information for CreateControlTable:

private static System.Web.UI.WebControls.Table
CreateControlTable(System.Data.DataTable datatable)

It seems that the error message is related with the controls on your web
application.

Paulo, according to the stack trace, it is really hard for me to find out
more information. Can you help to collect some additional information?
Thanks for your effort and time.

1. Please share the sample code which will cause the NullReferenceException
on your side. I will perform more research based on the code.

2. Please let me know the .NET Framework version you installed on the
machine, 1.0 or 1.1.

We can check this information in the Add or Remove Programs in the
Control Panel.

I look forward to hearing from you soon. Have a nice day!

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)Working on a Windows 2000 5.00.2195 SP2 and .NET Framework 1.

The application is working fine. I'm having trouble only with the trace

web.config
<?xml version="1.0" encoding="utf-8" ?><configuration><system.web><compilation defaultLanguage="c#" debug="true" /><customErrors mode="RemoteOnly" defaultRedirect="Erro.htm" /><authentication mode="None" /><authorization><allow users="*" /><!-- Allow all users --></authorization><trace enabled="true" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" /><sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes
cookieless="false" timeout="20" /><globalization requestEncoding="utf-8" responseEncoding="utf-8" /></system.web><appSettings><add key="ConnectionString" value="whatever" /></appSettings></configuration>
Hi Steve

I haven't been able to test your solution yet because the problem only shows up in the prodution DB

This problem shows up in the production server (Win2k Server 2000) and in the test server (Win3k). Not in my machine (WinXPpro)

The same thing happens if I add Trace="True" to the @. Page directive of WorkLog.asp

Shouldn't tracing be independent of the application

Paulo Morgad
Hi Paulo,

Yes, generally speaking "Trace" is seperate from application code. However,
some times trace will also report errors when there are some issues with
the configuration or code.

According to your last information, the error does not appear on the
Windows XP machine, I suggest that we perform the following steps to
further narrow down this issue besides running the sample application:

1. Create one empty web application on the production or test server.

2. Enable Trace to the "@.Page" directive.

3. Now, please check if there is any error message when running the web
application.

4. If everything is OK, add code like following to Page_Load:

Trace.Write("test");

5. Run the web application again and check if there is any error message.

If there is any new finding, feel free to let me know. Thanks!

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Hi Steve

I created another web application in the the test server (Win2k3) with another DB (no Northwind still)

I added the Trace="true" attribute to the @.Page directive and it throws the NullReferenceExcepetion

Without the Trace="true" attribute to the @.Page, the page works fine (the trace doesn't)

Regards

Paulo Morgado
Hi Paulo,

You means even a simple project will also suffer the problem on the win2k3
server ? If so, I suspect that whether the ASP.NET is correctdly installed
or is corrupted on the server machine. Would you please try reinstalling
the ASP.NET via the
"aspnet_regiis -i" in command in the vs.net commandline prompt?

For more detailed info on the aspnet_regiis tool, you may view the
following reference in MSDN:
#ASP.NET IIS Registration Tool (Aspnet_regiis.exe)
http://msdn.microsoft.com/library/e...netiisregistrat
iontoolaspnet_regiisexe.asp?frame=true

If you have any new findings, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Hi Steve

I ran aspnet_regiis -i on the test server (Win2k3) but, now, all requests to an .aspx page get the HTTP 404 error. All .htm are served rigth

I restarted IIS but, still the same

Paulo Morgado
Hi Paulo,

You mean after run the
aspnet_regiis -i in the commandline, all the aspx page on your machine
can't be requested(return 404 error)? If so, it doesn seems so strange.
Have you installed both .net framework1.0 and 1.1 on this machine? If so,
which version's regiis tool have you used?
the one under
F:\WINDOWS\Microsoft.NET\Framework\v1.0.3705
is for 1.0

and the one under
F:\WINDOWS\Microsoft.NET\Framework\v1.1.4322
is for 1.1

I think you can directly go to the
F:\WINDOWS\Microsoft.NET\Framework\v1.1.4322 folder and
run
aspnet_regiis -u to remove the asp.net and
then run
aspnet_regiis -i again to install and see whether it helps.

Also, since the 404 error is generally returned by IIS, I recommend that
you have a check in the IIS log to see whether it can provide any clues.
Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Hi Steve

Got ASP.NET working. Aplication Server\Internet Information Services (IIS) MAnager\Web Service extensions\ASP.NET v1.1.4322 -> Allow

The System.NullReferenceException on trace details remains

Regard
Paulo Morgado
Hi Paulo,

If you select "clear current trace", and then add some information to the
trace log and thow the trace details again, Can this fixed the problem?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

System.NullReferenceException on trace.axd

Hi Paulo,

I have checked the stack trace, this error can be related with
CreateControlTable.

We can also find the following information for CreateControlTable:

private static System.Web.UI.WebControls.Table
CreateControlTable(System.Data.DataTable datatable)

It seems that the error message is related with the controls on your web
application.

Paulo, according to the stack trace, it is really hard for me to find out
more information. Can you help to collect some additional information?
Thanks for your effort and time.

1. Please share the sample code which will cause the NullReferenceException
on your side. I will perform more research based on the code.

2. Please let me know the .NET Framework version you installed on the
machine, 1.0 or 1.1.

We can check this information in the Add or Remove Programs in the
Control Panel.

I look forward to hearing from you soon. Have a nice day!

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)Working on a Windows 2000 5.00.2195 SP2 and .NET Framework 1.

The application is working fine. I'm having trouble only with the trace

web.config
<?xml version="1.0" encoding="utf-8" ?><configuration><system.web><compilation defaultLanguage="c#" debug="true" /><customErrors mode="RemoteOnly" defaultRedirect="Erro.htm" /><authentication mode="None" /><authorization><allow users="*" /><!-- Allow all users --></authorization><trace enabled="true" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" /><sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes
cookieless="false" timeout="20" /><globalization requestEncoding="utf-8" responseEncoding="utf-8" /></system.web><appSettings><add key="ConnectionString" value="whatever" /></appSettings></configuration>

System.NullReferenceException on TextBox object...

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:
--
<%@dotnet.itags.org. Page Language="VB" Inherits="CustProfile" src="http://pics.10026.com/?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>
<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\CustPro
file.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 )Please disregard this post.
I think I've found a way using JavaScript.
"A. Nonymous" <anonymous@.hotmail.com> wrote in message
news:2PCdnXTBrr8cIXvcRVn-oQ@.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="http://pics.10026.com/?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>
>
> <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\CustPro
file.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 )
>
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" <anonymous@.hotmail.com> wrote in message
news:2PCdnXTBrr8cIXvcRVn-oQ@.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="http://pics.10026.com/?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>
>
> <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\CustPro
file.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 )
>

System.NullReferenceException on TextBox object...

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:
---

<%@dotnet.itags.org. Page Language="VB" Inherits="CustProfile" src="http://pics.10026.com/?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>

<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)Please disregard this post.

I think I've found a way using JavaScript.

"A. Nonymous" <anonymous@.hotmail.com> wrote in message
news:2PCdnXTBrr8cIXvcRVn-oQ@.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="http://pics.10026.com/?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>
>
> <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)
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" <anonymous@.hotmail.com> wrote in message
news:2PCdnXTBrr8cIXvcRVn-oQ@.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="http://pics.10026.com/?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>
>
> <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)

System.NullReferenceException raised on site

Hi folks. Just a client-side question to ask. Don't know if this is the
right place to ask for specific help. If not, sorry for the noise ;-)

Well, a friend of mine tries to access weightwatchers.fr and since a few
days, the site is unreachable at her home. She gets asp.net error
messages on her navigator telling her that there was on "object
reference not set to an instance of an object". The funny thing is that
she was able to connect last week. She is on Win2k. I made connection
tests on my side (Xp Pro SP1) and I cannot see any problem.

I'm a C++ developer and I work a bit with C# and .NET platform so I can
understand what the error message means. Although the error message is
server-side related, I can guess that there is something jerky on her
system, client side. I'm not very good at MS system managing and I need
a bit of advice about what's causing so much trouble.

If anybody could help, we would be very grateful.

Regards

--
SebEmail weightwatchers...the problem is with their site, not your friends
computer. However, had I to guess, I'd imagine she has a tool (norton) or
setting which blocks the UrlReferrer...and the folks at WW are doing
something like Request.UrlReferrer.ToString() when UrlReferrer is
nothing...that's ilke a 1 in a million guess though :)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)

"metalseb" <metalseb_nofuckinspamhere_@.free.fr> wrote in message
news:423e9eef$0$32564$636a15ce@.news.free.fr...
> Hi folks. Just a client-side question to ask. Don't know if this is the
> right place to ask for specific help. If not, sorry for the noise ;-)
> Well, a friend of mine tries to access weightwatchers.fr and since a few
> days, the site is unreachable at her home. She gets asp.net error
> messages on her navigator telling her that there was on "object
> reference not set to an instance of an object". The funny thing is that
> she was able to connect last week. She is on Win2k. I made connection
> tests on my side (Xp Pro SP1) and I cannot see any problem.
> I'm a C++ developer and I work a bit with C# and .NET platform so I can
> understand what the error message means. Although the error message is
> server-side related, I can guess that there is something jerky on her
> system, client side. I'm not very good at MS system managing and I need
> a bit of advice about what's causing so much trouble.
> If anybody could help, we would be very grateful.
> Regards
> --
> Seb
Seb,
the error type "object
reference not set to an instance of an object"
Try posting the line of the error it would be easier to help
Elaborate
Patrick

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Karl Seguin a crit :
> Email weightwatchers...the problem is with their site, not your friends
> computer. However, had I to guess, I'd imagine she has a tool (norton)or
> setting which blocks the UrlReferrer...and the folks at WW are doing
> something like Request.UrlReferrer.ToString() when UrlReferrer is
> nothing...that's ilke a 1 in a million guess though :)

Thanks Karl

Well, I think that there is some kind of firewall issue with her
machine. I will investigate this way. She phoned WW several times about
this bug and got (guess what) any answers. You know, all is running fine
on their side, so why should they investigate ?

--
Seb

System.NullReferenceException raised on site

Hi folks. Just a client-side question to ask. Don't know if this is the
right place to ask for specific help. If not, sorry for the noise ;-)
Well, a friend of mine tries to access weightwatchers.fr and since a few
days, the site is unreachable at her home. She gets asp.net error
messages on her navigator telling her that there was on "object
reference not set to an instance of an object". The funny thing is that
she was able to connect last w. She is on Win2k. I made connection
tests on my side (Xp Pro SP1) and I cannot see any problem.
I'm a C++ developer and I work a bit with C# and .NET platform so I can
understand what the error message means. Although the error message is
server-side related, I can guess that there is something jerky on her
system, client side. I'm not very good at MS system managing and I need
a bit of advice about what's causing so much trouble.
If anybody could help, we would be very grateful.
Regards
SebEmail weightwatchers...the problem is with their site, not your friends
computer. However, had I to guess, I'd imagine she has a tool (norton) or
setting which blocks the UrlReferrer...and the folks at WW are doing
something like Request.UrlReferrer.ToString() when UrlReferrer is
nothing...that's ilke a 1 in a million guess though :)
Karl
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"metalseb" <metalseb_noXXXXinspamhere_@.free.fr> wrote in message
news:423e9eef$0$32564$636a15ce@.news.free.fr...
> Hi folks. Just a client-side question to ask. Don't know if this is the
> right place to ask for specific help. If not, sorry for the noise ;-)
> Well, a friend of mine tries to access weightwatchers.fr and since a few
> days, the site is unreachable at her home. She gets asp.net error
> messages on her navigator telling her that there was on "object
> reference not set to an instance of an object". The funny thing is that
> she was able to connect last w. She is on Win2k. I made connection
> tests on my side (Xp Pro SP1) and I cannot see any problem.
> I'm a C++ developer and I work a bit with C# and .NET platform so I can
> understand what the error message means. Although the error message is
> server-side related, I can guess that there is something jerky on her
> system, client side. I'm not very good at MS system managing and I need
> a bit of advice about what's causing so much trouble.
> If anybody could help, we would be very grateful.
> Regards
> --
> Seb
Seb,
the error type "object
reference not set to an instance of an object"
Try posting the line of the error it would be easier to help
Elaborate
Patrick
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!
Karl Seguin a =E9crit :
> Email weightwatchers...the problem is with their site, not your friends=

> computer. However, had I to guess, I'd imagine she has a tool (norton)=
or
> setting which blocks the UrlReferrer...and the folks at WW are doing
> something like Request.UrlReferrer.ToString() when UrlReferrer is
> nothing...that's ilke a 1 in a million guess though :)
Thanks Karl
Well, I think that there is some kind of firewall issue with her=20
machine. I will investigate this way. She phoned WW several times about=20
this bug and got (guess what) any answers. You know, all is running fine =
on their side, so why should they investigate ?
--=20
Seb