Showing posts with label file. Show all posts
Showing posts with label file. Show all posts

Monday, March 26, 2012

Object reference error in UserControl's Load event

I have a UserControl that I declare programmatically as follows:

Dim userctrl as New rightside_portal()

The codebehind file for this UserControl looks like the following:

Partial Public Class rightside_portal : Inherits System.Web.UI.UserControl

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

Const renewurl As String = "http://www.renewingsite.com/"

Me.lblExpiresOn.Text = String.Format("IMPORTANT<br/>Your account is set to
expire {0}. To renew your membership, please ", "EXPIRATIONDATE")

Me.lnkRenew.NavigateUrl = renewurl

Me.lnkSaveToday.NavigateUrl = renewurl

End Sub

End Class

However, I receive the following error when I run the application:

Server Error in '/' Application.
------------------------

Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set
to 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
object.]
AFBE.rightside_portal.Page_Load(Object sender, EventArgs e) +59
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET
Version:2.0.50727.210

I am pretty sure the problem has something to do with the fact that I am
declaring the UserControl in my codebehind rather than my *.aspx file, but I
am not quite sure what I need to do differently. If anyone can help me, I
would appreciate it. Thanks.
--
Nathan Sokalski
njsokalski@dotnet.itags.org.hotmail.com
http://www.nathansokalski.com/you can't create a "new UserContorl();"

you need to use Page.LoadControl("~/controls/test.ascx");

Using "new" creates a new instance of the class, but doesn't instanticate
the aspx class. therefore lblExpires is never created and you end up with a
null reference.

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"Nathan Sokalski" <njsokalski@.hotmail.comwrote in message
news:Oiui$QWMHHA.992@.TK2MSFTNGP06.phx.gbl...

Quote:

Originally Posted by

>I have a UserControl that I declare programmatically as follows:
>
Dim userctrl as New rightside_portal()
>
The codebehind file for this UserControl looks like the following:
>
Partial Public Class rightside_portal : Inherits System.Web.UI.UserControl
>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
>
Const renewurl As String = "http://www.renewingsite.com/"
>
Me.lblExpiresOn.Text = String.Format("IMPORTANT<br/>Your account is set to
expire {0}. To renew your membership, please ", "EXPIRATIONDATE")
>
Me.lnkRenew.NavigateUrl = renewurl
>
Me.lnkSaveToday.NavigateUrl = renewurl
>
End Sub
>
End Class
>
>
However, I receive the following error when I run the application:
>
Server Error in '/' Application.
------------------------
>
Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set
to 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
object.]
AFBE.rightside_portal.Page_Load(Object sender, EventArgs e) +59
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
>
>
>
------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42;
ASP.NET Version:2.0.50727.210
>
I am pretty sure the problem has something to do with the fact that I am
declaring the UserControl in my codebehind rather than my *.aspx file, but
I am not quite sure what I need to do differently. If anyone can help me,
I would appreciate it. Thanks.
--
Nathan Sokalski
njsokalski@.hotmail.com
http://www.nathansokalski.com/
>

Object reference error in UserControl's Load event

I have a UserControl that I declare programmatically as follows:
Dim userctrl as New rightside_portal()
The codebehind file for this UserControl looks like the following:
Partial Public Class rightside_portal : Inherits System.Web.UI.UserControl
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Const renewurl As String = "http://www.renewingsite.com/"
Me.lblExpiresOn.Text = String.Format("IMPORTANT<br/>Your account is set to
expire {0}. To renew your membership, please ", "EXPIRATIONDATE")
Me.lnkRenew.NavigateUrl = renewurl
Me.lnkSaveToday.NavigateUrl = renewurl
End Sub
End Class
However, I receive the following error when I run the application:
Server Error in '/' Application.
----
--
Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set
to 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
object.]
AFBE.rightside_portal.Page_Load(Object sender, EventArgs e) +59
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
----
--
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET
Version:2.0.50727.210
I am pretty sure the problem has something to do with the fact that I am
declaring the UserControl in my codebehind rather than my *.aspx file, but I
am not quite sure what I need to do differently. If anyone can help me, I
would appreciate it. Thanks.
--
Nathan Sokalski
njsokalski@dotnet.itags.org.hotmail.com
http://www.nathansokalski.com/you can't create a "new UserContorl();"
you need to use Page.LoadControl("~/controls/test.ascx");
Using "new" creates a new instance of the class, but doesn't instanticate
the aspx class. therefore lblExpires is never created and you end up with a
null reference.
Karl
http://www.openmymind.net/
http://www.codebetter.com/
"Nathan Sokalski" <njsokalski@.hotmail.com> wrote in message
news:Oiui$QWMHHA.992@.TK2MSFTNGP06.phx.gbl...
>I have a UserControl that I declare programmatically as follows:
> Dim userctrl as New rightside_portal()
> The codebehind file for this UserControl looks like the following:
> Partial Public Class rightside_portal : Inherits System.Web.UI.UserControl
> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Me.Load
> Const renewurl As String = "http://www.renewingsite.com/"
> Me.lblExpiresOn.Text = String.Format("IMPORTANT<br/>Your account is set to
> expire {0}. To renew your membership, please ", "EXPIRATIONDATE")
> Me.lnkRenew.NavigateUrl = renewurl
> Me.lnkSaveToday.NavigateUrl = renewurl
> End Sub
> End Class
>
> However, I receive the following error when I run the application:
> Server Error in '/' Application.
> ----
--
> Object reference not set to an instance of an object.
> 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.NullReferenceException: Object reference not set
> to 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
> object.]
> AFBE.rightside_portal.Page_Load(Object sender, EventArgs e) +59
> System.Web.UI.Control.OnLoad(EventArgs e) +99
> System.Web.UI.Control.LoadRecursive() +47
> System.Web.UI.Control.LoadRecursive() +131
> System.Web.UI.Control.LoadRecursive() +131
> System.Web.UI.Control.LoadRecursive() +131
> System.Web.UI.Control.LoadRecursive() +131
> System.Web.UI.Page.ProcessRequestMain(Boolean
> includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
>
> ----
--
> Version Information: Microsoft .NET Framework Version:2.0.50727.42;
> ASP.NET Version:2.0.50727.210
> I am pretty sure the problem has something to do with the fact that I am
> declaring the UserControl in my codebehind rather than my *.aspx file, but
> I am not quite sure what I need to do differently. If anyone can help me,
> I would appreciate it. Thanks.
> --
> Nathan Sokalski
> njsokalski@.hotmail.com
> http://www.nathansokalski.com/
>

object reference not set to an instance of an object

Hello,

I am trying to use the ObjectDataSource, & the class file where I'm getting the error is this:

using

System;

using

System.Data;

using

System.Configuration;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

using

System.Data.SqlClient;

//SQL Server Data Layer to Players table

public

classPlayerLogic

{

public PlayerLogic()

{

}

privatestaticstring cs =ConfigurationManager.ConnectionStrings["BBDBA"].ConnectionString;publicstaticDataSet GetPlayers()

{

DataSet ds =newDataSet();SqlConnection cn =newSqlConnection(cs);

cn.Open();

SqlDataAdapter da =newSqlDataAdapter("dbo.usp_PlayersGetAll", cn);

da.Fill(ds);

cn.Close();

cn.Dispose();

return ds;

}

publicstaticDataSet GetPlayer(int PlayerID)

{

DataSet ds =newDataSet();SqlConnection cn =newSqlConnection(cs);SqlCommand cmd =newSqlCommand("dbo.usp_PlayersGetOne", cn);

cmd.CommandType =

CommandType.StoredProcedure;

cmd.Parameters.Add(

newSqlParameter("@dotnet.itags.org.PlayerID", PlayerID));

cn.Open();

SqlDataAdapter da =newSqlDataAdapter(cmd);

da.Fill(ds);

cn.Close();

cn.Dispose();

return ds;

}

publicstaticstring SavePlayer(Player1 MyPlayer)

{

SqlConnection cn =newSqlConnection(cs);SqlCommand cmd =newSqlCommand("dbo.usp_PlayerSave2005", cn);string err ="";string rtn ="";if ((Convert.ToInt32(MyPlayer.Rank) > 25) || (Convert.ToInt32(MyPlayer.Rank) < 0))

{

err =

"Rank must be between 0 & 25 ";

}

if (MyPlayer.PlayerName ==String.Empty)

{

err =

"PlayerName required";

}

if (err.Length == 0)

{

cmd.CommandType =

CommandType.StoredProcedure;

cmd.Parameters.Add(

newSqlParameter("@dotnet.itags.org.ErrMsg",SqlDbType.VarChar, 254));

cmd.Parameters[

"@dotnet.itags.org.ErrMsg"].Direction =ParameterDirection.Output;

cmd.Parameters.Add(

newSqlParameter("@dotnet.itags.org.NewID",SqlDbType.Int));

cmd.Parameters[

"@dotnet.itags.org.NewID"].Direction =ParameterDirection.Output;

cmd.Parameters.Add(

newSqlParameter("@dotnet.itags.org.PlayerID", MyPlayer.PlayerID));

cmd.Parameters.Add(

newSqlParameter("@dotnet.itags.org.PlayerName", MyPlayer.PlayerName));

cmd.Parameters.Add(

newSqlParameter("@dotnet.itags.org.Rank", MyPlayer.Rank));

cmd.Parameters.Add(

newSqlParameter("@dotnet.itags.org.HireDate", MyPlayer.HireDate));

cmd.Parameters.Add(

newSqlParameter("@dotnet.itags.org.PositionCode", MyPlayer.PositionCode));

cmd.Parameters.Add(

newSqlParameter("@dotnet.itags.org.Salary", MyPlayer.Salary));

cn.Open();

cmd.ExecuteNonQuery();

//err = cmd.Parameters["@dotnet.itags.org.ErrMsg"].Value.ToString();//rtn = cmd.Parameters["@dotnet.itags.org.NewID"].Value.ToString();

}

//if (err.Length > 0)//{// rtn = "*" + err;//}//else//{// rtn = cmd.Parameters["@dotnet.itags.org.NewID"].Value.ToString();//}

cn.Close();

cn.Dispose();

return rtn;

}

publicstaticint DeletePlayer(int PlayerID)

{

SqlConnection cn =newSqlConnection(cs);SqlCommand cmd =newSqlCommand("dbo.usp_PlayerDelete", cn);int rtn;

cmd.CommandType =

CommandType.StoredProcedure;

cn.Open();

rtn = cmd.ExecuteNonQuery();

cn.Close();

cn.Dispose();

return rtn;

}

}

The code where I'm calling the class from is:

using

System;

using

System.Data;

using

System.Configuration;

using

System.Collections;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

public

partialclassDefaultODS : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

lblMsg.Text =

"";

}

protectedvoid frvPlayer_DataBound(object sender,EventArgs e)

{

//if (frvPlayer.CurrentMode == FormViewMode.Edit)//{// LinkButton btn = new LinkButton();// btn = (LinkButton)frvPlayer.FindControl("btnDelete");// btn.Attributes.Add("onClick", "return confirm('Confirm your delete!')");//}

}

protectedvoid frvPlayer_ItemUpdated(object sender,FormViewUpdatedEventArgs e)

{

if (e.AffectedRows > 0)

{

grdPlayers.DataBind();

lblMsg.Text =

"PlayerID " + e.Keys["PlayerID"] +" " + e.NewValues["PlayerName"].ToString() +" Updated";

e.KeepInEditMode =

false;

}

else

{

e.KeepInEditMode =

true;

}

}

protectedvoid frvPlayer_ItemUpdating(object sender,FormViewUpdateEventArgs e)

{

lblMsg.Text =

"";if((Convert.ToInt32(e.NewValues["Rank"]) > 25) || ((Convert.ToInt32(e.NewValues["Rank"]) < 0)))

{

lblMsg.Text =

"Rank must be between 0 & 25 " +"; " + lblMsg.Text;

e.Cancel =

true;

}

if (e.NewValues["PlayerName"].ToString() ==String.Empty)

{

lblMsg.Text =

"Player name required";

e.Cancel =

true;

}

}

protectedvoid frvPlayer_ItemDeleted(object sender,FormViewDeletedEventArgs e)

{

if (e.AffectedRows > 0)

{

lblMsg.Text =

"PlayerID " + e.Keys["PlayerID"] +" " +

e.Values[

"PlayerName"].ToString() +" Deleted";

grdPlayers.DataBind();

frvPlayer.ChangeMode(

FormViewMode.ReadOnly);

}

else

{

lblMsg.Text =

"Error deleting record";

}

grdPlayers.DataBind();

}

protectedvoid frvPlayer_ItemInserted(object sender,FormViewInsertedEventArgs e)

{

if (e.AffectedRows > 0)

{

lblMsg.Text = e.Values[

"PlayerName"].ToString() +" Inserted";

grdPlayers.DataBind();

e.KeepInInsertMode =

false;

}

else

{

e.KeepInInsertMode =

true;

}

}

protectedvoid grdPlayers_RowUpdated(object sender,GridViewUpdatedEventArgs e)

{

if (e.AffectedRows > 0)

{

grdPlayers.DataBind();

lblMsg.Text =

"PlayerID# " + e.Keys["PlayerID"].ToString() +"- " +"Updated";

}

else

{

lblMsg.Text =

"Error updating record";

}

}

protectedvoid frvPlayer_ItemInserting(object sender,FormViewInsertEventArgs e)

{

lblMsg.Text =

"";if ((Convert.ToInt32(e.Values["Rank"]) < 0) || ((Convert.ToInt32(e.Values["Rank"]) > 25)))

{

lblMsg.Text =

"There can't be less than 0 players or more than 25";

e.Cancel =

true;

}

if (e.Values["PlayerName"].ToString() ==String.Empty)

{

lblMsg.Text =

"Player name required";

e.Cancel =

true;

}

}

//protected void frvPlayerDataSource_Inserting(object sender, SqlDataSourceCommandEventArgs e)//{// //set the insert flag// e.Command.Parameters["@dotnet.itags.org.PlayerID"].Value = 0;//}//protected void frvPlayerDataSource_Updated(object sender, SqlDataSourceStatusEventArgs e)//{// if(e.Command.Parameters["@dotnet.itags.org.ErrMsg"].Value.ToString().Length > 0)// {// lblMsg.Text = "<font color=red>" + e.Command.Parameters["@dotnet.itags.org.ErrMsg"].Value.ToString() + "</Font>";// }//}//protected void frvPlayerDataSource_Inserted(object sender, SqlDataSourceStatusEventArgs e)//{// if (e.Command.Parameters["@dotnet.itags.org.ErrMsg"].Value.ToString().Length > 0)// {// lblMsg.Text = "<font color=red>" + e.Command.Parameters["@dotnet.itags.org.ErrMsg"].Value.ToString() + "</Font>";// }//}

}

The error I get is this:

Server Error in '/DataSample10' Application.

Object reference not set to an instance of an object.

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.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 18: }Line 19:Line 20: private static string cs = ConfigurationManager.ConnectionStrings["BBDBA"].ConnectionString;Line 21: Line 22: public static DataSet GetPlayers()


Source File:c:\BegASPNET2\C#\DataSample10\App_Code\PlayerLogic.cs Line:20

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.] PlayerLogic..cctor() in c:\BegASPNET2\C#\DataSample10\App_Code\PlayerLogic.cs:20[TypeInitializationException: The type initializer for 'PlayerLogic' threw an exception.] PlayerLogic.GetPlayer(Int32 PlayerID) in c:\BegASPNET2\C#\DataSample10\App_Code\PlayerLogic.cs:53[TargetInvocationException: Exception has been thrown by the target of an invocation.] System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0 System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +72 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +358 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29 System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +17 System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +676 System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +2652 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +84 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +154 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +99 System.Web.UI.WebControls.FormView.DataBind() +23 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +91 System.Web.UI.WebControls.FormView.EnsureDataBound() +176 System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +101 System.Web.UI.Control.EnsureChildControls() +134 System.Web.UI.Control.PreRenderRecursiveInternal() +109 System.Web.UI.Control.PreRenderRecursiveInternal() +233 System.Web.UI.Control.PreRenderRecursiveInternal() +233 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4435



Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42

I'm a big newbie, so I'd appreciate any input you guys have!

Thanks,

Orbit

no one wants to read that all...

Find the line thats erroring and post JUST that relevant code.


check what it ConfigurationManager.ConnectionStrings["BBDBA"] in debug mode.

As curt_c said please post the relevant code


Hi Curt,

Sorry it was so verbose. As a newbie, I just wanted to be sure I didn't leave anything out. Thank you for your reply, however. I would post a culled version of the question, but "vtrajan" resolved the issue for me.

Thanks again,

Orbit


Dear "vtrajan",

Thank you, your suggestion resolved my issue. Debugging is an area I need to improve upon bigtime. And I'll take the suggestion to be more succinct in my question posts from now on.

Thanks again,

Orbit

Saturday, March 24, 2012

Object reference not set to an instance of an object

Hi
Any idea what's happening, please?! TIA, details....

I have a formA.aspx page and a corresponding class file formA.cs compiled
into a library. User is to fill out some information and click a submit
button to trigger a click event. Here is what I have in formA.cs

public Button btnSubmit

protected override void OnInit(EventArgs e)
{
btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
}
void btnSubmit_Click(Object sender, EventArgs e)
{
String domain, str_path, objName;
//code to create obj
if (IsValid) {
...
try
{
DirectoryEntry myDir = new DirectoryEntry(str_path);
...
}
catch (Exception Exception1)
{
System.Runtime.InteropServices.COMException COMEx =
(System.Runtime.InteropServices.COMException)Excep tion1;
//ConsoleWriteline(COMEx.ErrorCode);
}

//code to add UPN

//code to create LDAP files
}
}
--
Here is the Stack trace
[NullReferenceException: Object reference not set to an instance of an
object.]
NETDS.ouCreate.btnOUCreate_Click(Object sender, EventArgs e) +38
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
stBackEvent(String eventArgument) +57
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() +1292

--The error is in btnOUCreate_Cli*ck event. Need to see that code
Sorry, please see my other post ( Subject: ..... - newpost) TIA

"BillGatesFan" <klj_mcsd@.hotmail.com> wrote in message
news:1115695125.473044.62560@.f14g2000cwb.googlegro ups.com...
The error is in btnOUCreate_Cli*ck event. Need to see that code
Sorry, please see my other post ( Subject: ..... - newpost) TIA

"BillGatesFan" <klj_mcsd@.hotmail.com> wrote in message
news:1115695125.473044.62560@.f14g2000cwb.googlegro ups.com...
The error is in btnOUCreate_Cli*ck event. Need to see that code
What are u trying to do exactly?

"dl" wrote:

> Hi
> Any idea what's happening, please?! TIA, details....
> I have a formA.aspx page and a corresponding class file formA.cs compiled
> into a library. User is to fill out some information and click a submit
> button to trigger a click event. Here is what I have in formA.cs
> public Button btnSubmit
> protected override void OnInit(EventArgs e)
> {
> btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
> }
> void btnSubmit_Click(Object sender, EventArgs e)
> {
> String domain, str_path, objName;
> //code to create obj
> if (IsValid) {
> ...
> try
> {
> DirectoryEntry myDir = new DirectoryEntry(str_path);
> ...
> }
> catch (Exception Exception1)
> {
> System.Runtime.InteropServices.COMException COMEx =
> (System.Runtime.InteropServices.COMException)Excep tion1;
> //ConsoleWriteline(COMEx.ErrorCode);
> }
> //code to add UPN
> //code to create LDAP files
> }
> }
> --
> Here is the Stack trace
> [NullReferenceException: Object reference not set to an instance of an
> object.]
> NETDS.ouCreate.btnOUCreate_Click(Object sender, EventArgs e) +38
> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
> System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
> stBackEvent(String eventArgument) +57
> 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() +1292
>
> --
>
>

Object reference not set to an instance of an object

Coming from classic asp, I'm a bit in the dark here.

I want to dispaly the content of a file in a literal server control.

I've created a class utils.vb

Imports System.IO

Public Class Utils
Inherits System.Web.UI.Page
Public Function ReadFile(ByVal pFile) ' As String
Dim ForReading As Integer = 1
Dim fso As Object
Dim ts
Dim s
fso = CreateObject("Scripting.FileSystemObject")
ts = fso.OpenTextFile(MapPath(pFile), ForReading)
s = ts.ReadAll
ts.Close()
ReadFile = s
End Function
End Class

on the aspx page I use

Dim utl As Utils = New Utils
Dim lBody As String = utl.ReadFile( strFile )

litContent.Text = lBody

If I have the ReadFile function in the code behind page of the calling
aspx page it works.

When I move the function to the utils.vb class I get the following
error:

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

Line 11: Dim s
Line 12: fso = CreateObject("Scripting.FileSystemObject")
Line 13: ts = fso.OpenTextFile(MapPath(pFile), ForReading)
Line 14: s = ts.ReadAll
Line 15: ts.Close()

Source File: c:\inetpub\wwwroot\project\Utils.vb Line: 13

I figure its the dim ts part of ReadFile function. But ...?

/MortenHi, hainsiman,

It is the call to MapPath() that is throwing the exception. Try:

HttpContext.Current.Server.MapPath()

instead.

Greetings
Martin
"hansiman" <hansi@.hotmail.com> wrote in message
news:s0fr30hrhlqctbupmovvkspidhj4m5v5nr@.4ax.com...
> Coming from classic asp, I'm a bit in the dark here.
> I want to dispaly the content of a file in a literal server control.
> I've created a class utils.vb
> Imports System.IO
> Public Class Utils
> Inherits System.Web.UI.Page
> Public Function ReadFile(ByVal pFile) ' As String
> Dim ForReading As Integer = 1
> Dim fso As Object
> Dim ts
> Dim s
> fso = CreateObject("Scripting.FileSystemObject")
> ts = fso.OpenTextFile(MapPath(pFile), ForReading)
> s = ts.ReadAll
> ts.Close()
> ReadFile = s
> End Function
> End Class
> on the aspx page I use
> Dim utl As Utils = New Utils
> Dim lBody As String = utl.ReadFile( strFile )
> litContent.Text = lBody
> If I have the ReadFile function in the code behind page of the calling
> aspx page it works.
> When I move the function to the utils.vb class I get the following
> error:
> System.NullReferenceException: Object reference not set to an instance
> of an object
> Line 11: Dim s
> Line 12: fso = CreateObject("Scripting.FileSystemObject")
> Line 13: ts = fso.OpenTextFile(MapPath(pFile), ForReading)
> Line 14: s = ts.ReadAll
> Line 15: ts.Close()
> Source File: c:\inetpub\wwwroot\project\Utils.vb Line: 13
> I figure its the dim ts part of ReadFile function. But ...?
> /Morten
Hi Martin

I still get the error even when I change the mappath part (see below).
The strange thing is that if I put the ReadFile function in the code
behind page of the aspx file it works with simply MatPath (pFile)...

utils.vb

Public Function ReadFile(ByVal pFile)
Dim ForReading As Integer = 1
Dim fso As Object = CreateObject("Scripting.FileSystemObject")
Dim ts, s
ts =
fso.OpenTextFile(MapPath(HttpContext.Current.Serve r.MapPath(pFile)),
ForReading)
s = ts.ReadAll
ts.Close()
ReadFile = s
End Function

Call from aspx file:

Dim utl As Utils = New Utils
Dim lBody As String = utl.ReadFile( strFile )
litContent.Text = lBody

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

Source Error:

Line 11: Dim ts, s
Line 12: 'ts = fso.OpenTextFile(MapPath(pFile), ForReading)
Line 13: ts =
fso.OpenTextFile(MapPath(HttpContext.Current.Serve r.MapPath(pFile)),
ForReading)
Line 14: s = ts.ReadAll
Line 15: ts.Close()

Source File: c:\inetpub\wwwroot\customersurveyanalysis\mmaUtils .vb
Line: 13

On Thu, 26 Feb 2004 10:47:31 +0100, "Martin Dechev"
<detcheff_@.hotmail.com> wrote:

>Hi, hainsiman,
>It is the call to MapPath() that is throwing the exception. Try:
>HttpContext.Current.Server.MapPath()
>instead.
>Greetings
>Martin
>"hansiman" <hansi@.hotmail.com> wrote in message
>news:s0fr30hrhlqctbupmovvkspidhj4m5v5nr@.4ax.com...
>> Coming from classic asp, I'm a bit in the dark here.
>>
>> I want to dispaly the content of a file in a literal server control.
>>
>> I've created a class utils.vb
>>
>> Imports System.IO
>>
>> Public Class Utils
>> Inherits System.Web.UI.Page
>> Public Function ReadFile(ByVal pFile) ' As String
>> Dim ForReading As Integer = 1
>> Dim fso As Object
>> Dim ts
>> Dim s
>> fso = CreateObject("Scripting.FileSystemObject")
>> ts = fso.OpenTextFile(MapPath(pFile), ForReading)
>> s = ts.ReadAll
>> ts.Close()
>> ReadFile = s
>> End Function
>> End Class
>>
>> on the aspx page I use
>>
>> Dim utl As Utils = New Utils
>> Dim lBody As String = utl.ReadFile( strFile )
>>
>> litContent.Text = lBody
>>
>> If I have the ReadFile function in the code behind page of the calling
>> aspx page it works.
>>
>> When I move the function to the utils.vb class I get the following
>> error:
>>
>> System.NullReferenceException: Object reference not set to an instance
>> of an object
>>
>> Line 11: Dim s
>> Line 12: fso = CreateObject("Scripting.FileSystemObject")
>> Line 13: ts = fso.OpenTextFile(MapPath(pFile), ForReading)
>> Line 14: s = ts.ReadAll
>> Line 15: ts.Close()
>>
>> Source File: c:\inetpub\wwwroot\project\Utils.vb Line: 13
>>
>> I figure its the dim ts part of ReadFile function. But ...?
>>
>> /Morten
>
> fso.OpenTextFile(MapPath(HttpContext.Current.Serve r.MapPath(pFile)),

should be:

fso.OpenTextFile(HttpContext.Current.Server.MapPat h(pFile)),

Greetings
Martin
ahhh, of course... thanx

On Fri, 27 Feb 2004 14:14:23 +0100, "Martin Dechev"
<detcheff_@.hotmail.com> wrote:

>> fso.OpenTextFile(MapPath(HttpContext.Current.Serve r.MapPath(pFile)),
>should be:
>fso.OpenTextFile(HttpContext.Current.Server.MapPat h(pFile)),
>Greetings
>Martin

Object reference not set to an instance of an object

Hi
Any idea what's happening, please?! TIA, details....
I have a formA.aspx page and a corresponding class file formA.cs compiled
into a library. User is to fill out some information and click a submit
button to trigger a click event. Here is what I have in formA.cs
public Button btnSubmit
protected override void OnInit(EventArgs e)
{
btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
}
void btnSubmit_Click(Object sender, EventArgs e)
{
String domain, str_path, objName;
//code to create obj
if (IsValid) {
..
try
{
DirectoryEntry myDir = new DirectoryEntry(str_path);
..
}
catch (Exception Exception1)
{
System.Runtime.InteropServices.COMException COMEx =
(System.Runtime.InteropServices.COMException)Exception1;
//ConsoleWriteline(COMEx.ErrorCode);
}
//code to add UPN
//code to create LDAP files
}
}
--
Here is the Stack trace
[NullReferenceException: Object reference not set to an instance of an
object.]
NETDS.ouCreate.btnOUCreate_Click(Object sender, EventArgs e) +38
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
stBackEvent(String eventArgument) +57
System.Web.UI.Page. RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1292The error is in btnOUCreate_Cli=ADck event. Need to see that code
Sorry, please see my other post ( Subject: ..... - newpost) TIA
"BillGatesFan" <klj_mcsd@.hotmail.com> wrote in message
news:1115695125.473044.62560@.f14g2000cwb.googlegroups.com...
The error is in btnOUCreate_Cli_ck event. Need to see that code
Sorry, please see my other post ( Subject: ..... - newpost) TIA
"BillGatesFan" <klj_mcsd@.hotmail.com> wrote in message
news:1115695125.473044.62560@.f14g2000cwb.googlegroups.com...
The error is in btnOUCreate_Cli_ck event. Need to see that code
What are u trying to do exactly?
"dl" wrote:

> Hi
> Any idea what's happening, please?! TIA, details....
> I have a formA.aspx page and a corresponding class file formA.cs compiled
> into a library. User is to fill out some information and click a submit
> button to trigger a click event. Here is what I have in formA.cs
> public Button btnSubmit
> protected override void OnInit(EventArgs e)
> {
> btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click
);
> }
> void btnSubmit_Click(Object sender, EventArgs e)
> {
> String domain, str_path, objName;
> //code to create obj
> if (IsValid) {
> ...
> try
> {
> DirectoryEntry myDir = new DirectoryEntry(str_path);
> ...
> }
> catch (Exception Exception1)
> {
> System.Runtime.InteropServices.COMException COMEx =
> (System.Runtime.InteropServices.COMException)Exception
1;
> //ConsoleWriteline(COMEx.ErrorCode);
> }
> //code to add UPN
> //code to create LDAP files
> }
> }
> --
> Here is the Stack trace
> [NullReferenceException: Object reference not set to an instance of an
> object.]
> NETDS.ouCreate.btnOUCreate_Click(Object sender, EventArgs e) +38
> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
> System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.Raise
Po
> stBackEvent(String eventArgument) +57
> System.Web.UI.Page. RaisePostBackEvent(IPostBackEventHandler
> sourceControl, String eventArgument) +18
> System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
> System.Web.UI.Page.ProcessRequestMain() +1292
>
> --
>
>

Object reference not set to an instance of an object - newpost

Hi
Any idea what's happening, please?! TIA, details....
I have a formA.aspx page and a corresponding class file formA.cs compiled
into a library. User is to fill out some information and click a submit
button to trigger a click event. Here is what I have in formA.cs
{
public Button btnOUCreate;
public Label Label1;
public TextBox txtACNo, txtCompanyName;
public ouCreate() {
}
void InitializeComponent()
{
btnOUCreate.Click += new
System.EventHandler(this.btnOUCreate_Click);
}
protected override void OnInit(EventArgs e)
{
this.InitializeComponent();
base.OnInit(e);
//throw new Exception("The method or operation is not
implemented.");
}
void Page_Load(object sender, EventArgs e)
{
//IPrincipal myPrincipal = this.User;
Label1.Text = HttpContext.Current.User.Identity.Name;
}
void btnOUCreate_Click(Object sender, EventArgs e)
{
String domain, str_path, newOUName;
//code to create OU
if (IsValid) {
newOUName = txtACNo.Text;
domain =
System.Configuration.ConfigurationSettings.AppSettings["DN"];
str_path = "LDAP://" + domain;
try
{
DirectoryEntry myDir = new DirectoryEntry(str_path);
DirectoryEntry newOU = myDir.Children.Add(newOUName, "OU");
}
catch (Exception Exception1)
{
System.Runtime.InteropServices.COMException COMEx =
(System.Runtime.InteropServices.COMException)Exception1;
//ConsoleWriteline(COMEx.ErrorCode);
}
//code to add UPN
}
}
}
Here is the Stack trace
[NullReferenceException: Object reference not set to an instance of an
object.]
NETDS.ouCreate.btnOUCreate_Click(Object sender, EventArgs e) +38
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
stBackEvent(String eventArgument) +57
System.Web.UI.Page. RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1292use the VS debugger and step through it...
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
<dl> wrote in message news:OCp9zDRVFHA.1508@.tk2msftngp13.phx.gbl...
> Hi
> Any idea what's happening, please?! TIA, details....
> I have a formA.aspx page and a corresponding class file formA.cs compiled
> into a library. User is to fill out some information and click a submit
> button to trigger a click event. Here is what I have in formA.cs
> {
> public Button btnOUCreate;
> public Label Label1;
> public TextBox txtACNo, txtCompanyName;
> public ouCreate() {
> }
> void InitializeComponent()
> {
> btnOUCreate.Click += new
> System.EventHandler(this.btnOUCreate_Click);
> }
> protected override void OnInit(EventArgs e)
> {
> this.InitializeComponent();
> base.OnInit(e);
> //throw new Exception("The method or operation is not
> implemented.");
> }
> void Page_Load(object sender, EventArgs e)
> {
> //IPrincipal myPrincipal = this.User;
> Label1.Text = HttpContext.Current.User.Identity.Name;
> }
> void btnOUCreate_Click(Object sender, EventArgs e)
> {
> String domain, str_path, newOUName;
> //code to create OU
> if (IsValid) {
> newOUName = txtACNo.Text;
> domain =
> System.Configuration.ConfigurationSettings.AppSettings["DN"];
> str_path = "LDAP://" + domain;
> try
> {
> DirectoryEntry myDir = new DirectoryEntry(str_path);
> DirectoryEntry newOU = myDir.Children.Add(newOUName, "OU");
> }
> catch (Exception Exception1)
> {
> System.Runtime.InteropServices.COMException COMEx =
> (System.Runtime.InteropServices.COMException)Exception1;
> //ConsoleWriteline(COMEx.ErrorCode);
> }
> //code to add UPN
> }
> }
> }
> --
> Here is the Stack trace
> [NullReferenceException: Object reference not set to an instance of an
> object.]
> NETDS.ouCreate.btnOUCreate_Click(Object sender, EventArgs e) +38
> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
> System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.Raise
Po
> stBackEvent(String eventArgument) +57
> System.Web.UI.Page. RaisePostBackEvent(IPostBackEventHandler
> sourceControl, String eventArgument) +18
> System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
> System.Web.UI.Page.ProcessRequestMain() +1292
>
> --
>
>
I don't have VS yet ?! will VWD2005 express do it? any other ways to do it?
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:OjiLhFRVFHA.928@.TK2MSFTNGP15.phx.gbl...
> use the VS debugger and step through it...
> --
> Curt Christianson
> Site & Scripts: http://www.Darkfalz.com
> Blog: http://blog.Darkfalz.com
>
> <dl> wrote in message news:OCp9zDRVFHA.1508@.tk2msftngp13.phx.gbl...
compiled
"OU");
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
+33
>
well, start taking out and putting back in some of the code till you limit
it down
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
<dl> wrote in message news:e7Kc8IRVFHA.3532@.TK2MSFTNGP09.phx.gbl...
>I don't have VS yet ?! will VWD2005 express do it? any other ways to do
>it?
> "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
> news:OjiLhFRVFHA.928@.TK2MSFTNGP15.phx.gbl...
> compiled
> "OU");
> System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.Raise
Po
> +33
>
Sorry, problem fixed, -- Wrong control type (HTML controls are used rather
than the Web controls).
<dl> wrote in message news:OCp9zDRVFHA.1508@.tk2msftngp13.phx.gbl...
> Hi
> Any idea what's happening, please?! TIA, details....
> I have a formA.aspx page and a corresponding class file formA.cs compiled
> into a library. User is to fill out some information and click a submit
> button to trigger a click event. Here is what I have in formA.cs
> {
> public Button btnOUCreate;
> public Label Label1;
> public TextBox txtACNo, txtCompanyName;
> public ouCreate() {
> }
> void InitializeComponent()
> {
> btnOUCreate.Click += new
> System.EventHandler(this.btnOUCreate_Click);
> }
> protected override void OnInit(EventArgs e)
> {
> this.InitializeComponent();
> base.OnInit(e);
> //throw new Exception("The method or operation is not
> implemented.");
> }
> void Page_Load(object sender, EventArgs e)
> {
> //IPrincipal myPrincipal = this.User;
> Label1.Text = HttpContext.Current.User.Identity.Name;
> }
> void btnOUCreate_Click(Object sender, EventArgs e)
> {
> String domain, str_path, newOUName;
> //code to create OU
> if (IsValid) {
> newOUName = txtACNo.Text;
> domain =
> System.Configuration.ConfigurationSettings.AppSettings["DN"];
> str_path = "LDAP://" + domain;
> try
> {
> DirectoryEntry myDir = new DirectoryEntry(str_path);
> DirectoryEntry newOU = myDir.Children.Add(newOUName,
"OU");
> }
> catch (Exception Exception1)
> {
> System.Runtime.InteropServices.COMException COMEx =
>
(System.Runtime.InteropServices.COMException)Exception1;
> //ConsoleWriteline(COMEx.ErrorCode);
> }
> //code to add UPN
> }
> }
> }
> --
> Here is the Stack trace
> [NullReferenceException: Object reference not set to an instance of an
> object.]
> NETDS.ouCreate.btnOUCreate_Click(Object sender, EventArgs e) +38
> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
>
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
> stBackEvent(String eventArgument) +57
> System.Web.UI.Page. RaisePostBackEvent(IPostBackEventHandler
> sourceControl, String eventArgument) +18
> System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
> System.Web.UI.Page.ProcessRequestMain() +1292
>
> --
>
>
Guess you were not declaring them properly
Patrick
*** Sent via Developersdex http://www.examnotes.net ***

Object reference not set to an instance of an object - newpost

Hi
Any idea what's happening, please?! TIA, details....

I have a formA.aspx page and a corresponding class file formA.cs compiled
into a library. User is to fill out some information and click a submit
button to trigger a click event. Here is what I have in formA.cs

{
public Button btnOUCreate;
public Label Label1;
public TextBox txtACNo, txtCompanyName;

public ouCreate() {
}

void InitializeComponent()
{
btnOUCreate.Click += new
System.EventHandler(this.btnOUCreate_Click);
}
protected override void OnInit(EventArgs e)
{
this.InitializeComponent();
base.OnInit(e);
//throw new Exception("The method or operation is not
implemented.");
}
void Page_Load(object sender, EventArgs e)
{
//IPrincipal myPrincipal = this.User;
Label1.Text = HttpContext.Current.User.Identity.Name;

}
void btnOUCreate_Click(Object sender, EventArgs e)
{
String domain, str_path, newOUName;
//code to create OU
if (IsValid) {
newOUName = txtACNo.Text;
domain =
System.Configuration.ConfigurationSettings.AppSett ings["DN"];
str_path = "LDAP://" + domain;
try
{
DirectoryEntry myDir = new DirectoryEntry(str_path);
DirectoryEntry newOU = myDir.Children.Add(newOUName, "OU");
}
catch (Exception Exception1)
{
System.Runtime.InteropServices.COMException COMEx =
(System.Runtime.InteropServices.COMException)Excep tion1;
//ConsoleWriteline(COMEx.ErrorCode);
}

//code to add UPN

}
}
}

--
Here is the Stack trace
[NullReferenceException: Object reference not set to an instance of an
object.]
NETDS.ouCreate.btnOUCreate_Click(Object sender, EventArgs e) +38
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
stBackEvent(String eventArgument) +57
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() +1292

--use the VS debugger and step through it...

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com

<dl> wrote in message news:OCp9zDRVFHA.1508@.tk2msftngp13.phx.gbl...
> Hi
> Any idea what's happening, please?! TIA, details....
> I have a formA.aspx page and a corresponding class file formA.cs compiled
> into a library. User is to fill out some information and click a submit
> button to trigger a click event. Here is what I have in formA.cs
> {
> public Button btnOUCreate;
> public Label Label1;
> public TextBox txtACNo, txtCompanyName;
> public ouCreate() {
> }
> void InitializeComponent()
> {
> btnOUCreate.Click += new
> System.EventHandler(this.btnOUCreate_Click);
> }
> protected override void OnInit(EventArgs e)
> {
> this.InitializeComponent();
> base.OnInit(e);
> //throw new Exception("The method or operation is not
> implemented.");
> }
> void Page_Load(object sender, EventArgs e)
> {
> //IPrincipal myPrincipal = this.User;
> Label1.Text = HttpContext.Current.User.Identity.Name;
> }
> void btnOUCreate_Click(Object sender, EventArgs e)
> {
> String domain, str_path, newOUName;
> //code to create OU
> if (IsValid) {
> newOUName = txtACNo.Text;
> domain =
> System.Configuration.ConfigurationSettings.AppSett ings["DN"];
> str_path = "LDAP://" + domain;
> try
> {
> DirectoryEntry myDir = new DirectoryEntry(str_path);
> DirectoryEntry newOU = myDir.Children.Add(newOUName, "OU");
> }
> catch (Exception Exception1)
> {
> System.Runtime.InteropServices.COMException COMEx =
> (System.Runtime.InteropServices.COMException)Excep tion1;
> //ConsoleWriteline(COMEx.ErrorCode);
> }
> //code to add UPN
> }
> }
> }
> --
> Here is the Stack trace
> [NullReferenceException: Object reference not set to an instance of an
> object.]
> NETDS.ouCreate.btnOUCreate_Click(Object sender, EventArgs e) +38
> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
> System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
> stBackEvent(String eventArgument) +57
> 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() +1292
>
> --
I don't have VS yet ?! will VWD2005 express do it? any other ways to do it?

"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:OjiLhFRVFHA.928@.TK2MSFTNGP15.phx.gbl...
> use the VS debugger and step through it...
> --
> Curt Christianson
> Site & Scripts: http://www.Darkfalz.com
> Blog: http://blog.Darkfalz.com
>
> <dl> wrote in message news:OCp9zDRVFHA.1508@.tk2msftngp13.phx.gbl...
> > Hi
> > Any idea what's happening, please?! TIA, details....
> > I have a formA.aspx page and a corresponding class file formA.cs
compiled
> > into a library. User is to fill out some information and click a submit
> > button to trigger a click event. Here is what I have in formA.cs
> > {
> > public Button btnOUCreate;
> > public Label Label1;
> > public TextBox txtACNo, txtCompanyName;
> > public ouCreate() {
> > }
> > void InitializeComponent()
> > {
> > btnOUCreate.Click += new
> > System.EventHandler(this.btnOUCreate_Click);
> > }
> > protected override void OnInit(EventArgs e)
> > {
> > this.InitializeComponent();
> > base.OnInit(e);
> > //throw new Exception("The method or operation is not
> > implemented.");
> > }
> > void Page_Load(object sender, EventArgs e)
> > {
> > //IPrincipal myPrincipal = this.User;
> > Label1.Text = HttpContext.Current.User.Identity.Name;
> > }
> > void btnOUCreate_Click(Object sender, EventArgs e)
> > {
> > String domain, str_path, newOUName;
> > //code to create OU
> > if (IsValid) {
> > newOUName = txtACNo.Text;
> > domain =
> > System.Configuration.ConfigurationSettings.AppSett ings["DN"];
> > str_path = "LDAP://" + domain;
> > try
> > {
> > DirectoryEntry myDir = new DirectoryEntry(str_path);
> > DirectoryEntry newOU = myDir.Children.Add(newOUName,
"OU");
> > }
> > catch (Exception Exception1)
> > {
> > System.Runtime.InteropServices.COMException COMEx =
> > (System.Runtime.InteropServices.COMException)Excep tion1;
> > //ConsoleWriteline(COMEx.ErrorCode);
> > }
> > //code to add UPN
> > }
> > }
> > }
> > --
> > Here is the Stack trace
> > [NullReferenceException: Object reference not set to an instance of an
> > object.]
> > NETDS.ouCreate.btnOUCreate_Click(Object sender, EventArgs e) +38
> > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
> > stBackEvent(String eventArgument) +57
> > 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() +1292
> > --
well, start taking out and putting back in some of the code till you limit
it down

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com

<dl> wrote in message news:e7Kc8IRVFHA.3532@.TK2MSFTNGP09.phx.gbl...
>I don't have VS yet ?! will VWD2005 express do it? any other ways to do
>it?
> "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
> news:OjiLhFRVFHA.928@.TK2MSFTNGP15.phx.gbl...
>> use the VS debugger and step through it...
>>
>> --
>> Curt Christianson
>> Site & Scripts: http://www.Darkfalz.com
>> Blog: http://blog.Darkfalz.com
>>
>>
>> <dl> wrote in message news:OCp9zDRVFHA.1508@.tk2msftngp13.phx.gbl...
>> > Hi
>> > Any idea what's happening, please?! TIA, details....
>>> > I have a formA.aspx page and a corresponding class file formA.cs
> compiled
>> > into a library. User is to fill out some information and click a
>> > submit
>> > button to trigger a click event. Here is what I have in formA.cs
>>> > {
>> > public Button btnOUCreate;
>> > public Label Label1;
>> > public TextBox txtACNo, txtCompanyName;
>>> > public ouCreate() {
>> > }
>>> > void InitializeComponent()
>> > {
>> > btnOUCreate.Click += new
>> > System.EventHandler(this.btnOUCreate_Click);
>> > }
>> > protected override void OnInit(EventArgs e)
>> > {
>> > this.InitializeComponent();
>> > base.OnInit(e);
>> > //throw new Exception("The method or operation is not
>> > implemented.");
>> > }
>> > void Page_Load(object sender, EventArgs e)
>> > {
>> > //IPrincipal myPrincipal = this.User;
>> > Label1.Text = HttpContext.Current.User.Identity.Name;
>>> > }
>> > void btnOUCreate_Click(Object sender, EventArgs e)
>> > {
>> > String domain, str_path, newOUName;
>> > //code to create OU
>> > if (IsValid) {
>> > newOUName = txtACNo.Text;
>> > domain =
>> > System.Configuration.ConfigurationSettings.AppSett ings["DN"];
>> > str_path = "LDAP://" + domain;
>> > try
>> > {
>> > DirectoryEntry myDir = new DirectoryEntry(str_path);
>> > DirectoryEntry newOU = myDir.Children.Add(newOUName,
> "OU");
>> > }
>> > catch (Exception Exception1)
>> > {
>> > System.Runtime.InteropServices.COMException COMEx =
>>> > (System.Runtime.InteropServices.COMException)Excep tion1;
>> > //ConsoleWriteline(COMEx.ErrorCode);
>> > }
>>> > //code to add UPN
>>> > }
>> > }
>> > }
>>> > --
>> > Here is the Stack trace
>> > [NullReferenceException: Object reference not set to an instance of an
>> > object.]
>> > NETDS.ouCreate.btnOUCreate_Click(Object sender, EventArgs e) +38
>> > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
>>> System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
>> > stBackEvent(String eventArgument) +57
>> > 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() +1292
>>>> > --
>>>>>
>>
Sorry, problem fixed, -- Wrong control type (HTML controls are used rather
than the Web controls).

<dl> wrote in message news:OCp9zDRVFHA.1508@.tk2msftngp13.phx.gbl...
> Hi
> Any idea what's happening, please?! TIA, details....
> I have a formA.aspx page and a corresponding class file formA.cs compiled
> into a library. User is to fill out some information and click a submit
> button to trigger a click event. Here is what I have in formA.cs
> {
> public Button btnOUCreate;
> public Label Label1;
> public TextBox txtACNo, txtCompanyName;
> public ouCreate() {
> }
> void InitializeComponent()
> {
> btnOUCreate.Click += new
> System.EventHandler(this.btnOUCreate_Click);
> }
> protected override void OnInit(EventArgs e)
> {
> this.InitializeComponent();
> base.OnInit(e);
> //throw new Exception("The method or operation is not
> implemented.");
> }
> void Page_Load(object sender, EventArgs e)
> {
> //IPrincipal myPrincipal = this.User;
> Label1.Text = HttpContext.Current.User.Identity.Name;
> }
> void btnOUCreate_Click(Object sender, EventArgs e)
> {
> String domain, str_path, newOUName;
> //code to create OU
> if (IsValid) {
> newOUName = txtACNo.Text;
> domain =
> System.Configuration.ConfigurationSettings.AppSett ings["DN"];
> str_path = "LDAP://" + domain;
> try
> {
> DirectoryEntry myDir = new DirectoryEntry(str_path);
> DirectoryEntry newOU = myDir.Children.Add(newOUName,
"OU");
> }
> catch (Exception Exception1)
> {
> System.Runtime.InteropServices.COMException COMEx =
(System.Runtime.InteropServices.COMException)Excep tion1;
> //ConsoleWriteline(COMEx.ErrorCode);
> }
> //code to add UPN
> }
> }
> }
> --
> Here is the Stack trace
> [NullReferenceException: Object reference not set to an instance of an
> object.]
> NETDS.ouCreate.btnOUCreate_Click(Object sender, EventArgs e) +38
> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
>
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
> stBackEvent(String eventArgument) +57
> 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() +1292
>
> --
Guess you were not declaring them properly
Patrick

*** Sent via Developersdex http://www.developersdex.com ***

Object reference not set to an instance of an object (problem using fileupload in codebehi

I am using file upload and when tying to get the uploaded file it is saying "object reference not set to an instance of an object" I even tried to get the control but still no luck. Can anybody give the solution for this. I have searched many topics related to this forum and even in web but nothing seems to working. Posting my code below,

upload.aspx

<

asp:ViewID="loadingData"runat="server"><asp:ImageID="Image2"onmouseover="changeTabPicture(id)"onmouseout="changeTabPictureBack(id)"runat="server"ImageUrl="~/Images/SelectOff.gif"/><asp:ImageID="Image4"runat="server"ImageUrl="~/Images/LoadOn.gif"/><asp:ImageID="Image9"onmouseover="changeTabPicture(id)"onmouseout="changeTabPictureBack(id)"runat="server"ImageUrl="~/Images/EditOff.gif"/><asp:ImageID="Image10"onmouseover="changeTabPicture(id)"onmouseout="changeTabPictureBack(id)"runat="server"ImageUrl="~/Images/FinalizeOff.gif"/><br/><asp:WebPartZoneID="LoadingWebPart"runat="server"BorderColor="#CCCCCC"Font-Names="Verdana"Padding="6"><ZoneTemplate><asp:PanelID="uploadPanel"runat="server"Height="50px"Width="125px"Enabled=true>"align="left"bgcolor="lemonchiffon"border="1"bordercolor="firebrick"style="height: 158px"visible="true"width="180">

<asp:FileUploadID="OFDSelectFile"runat="server"Width="286"Enabled=true/>

<asp:button id="button1" runat=server onClick="Submit_Click"/>

</zonetemplate>

upload.aspx.cs

protected void submit_click(object sender, evenetargs e)

{

string filepath = OFDSelectFile.PostedFile.FileName; //it gives error in this place

}

Let me know as soon as possible I have a demo to do on monday.

Are you declaring your OFDSelectFile at the top of your code-behind page? When you add a control to your HTML page it isn't added to the code-behind unless you flip your HTML to design-view. It's a little gotcha thing. If you are not declaring your OFDSelectFile at the top then add it manually, or try the design view trick.

I tried to define soemthing like this "protected System.Web.UI.WebControls.FileUpload OFDSelectFile;" on the code-behind but it says the page already has the definition for it. Can you please elaborate on how to use it or if there is any other trick please let me know.


dev_discuss:

I tried to define soemthing like this "protected System.Web.UI.WebControls.FileUpload OFDSelectFile;" on the code-behind but it says the page already has the definition for it. Can you please elaborate on how to use it or if there is any other trick please let me know.

You may want to turn on Tracing and look int he "Control Tree" to confirm that the generated ID of the control indeed is *just* "OFDSelectFile"

for info on ID's and Naming Containers, check out this good article:
http://odetocode.com/Blogs/scott/archive/2006/03/12/3091.aspx


Hi,

I am not sure completely how to get the id of the control, I had this code worked on other aspx page but I integrated my code with other and it is at that point it started not to work. One difference I found when I moved the code in the code behind I had something like "public partialclass Import : System.Web.UI.UserControl" for which the above code was working but when I copied and pasted my code in another page which had "public partial class _Default:Syste.web.ui.page" and the above code is not working .

I am not sure whether this is the reason it is not working because I had this code working in other pages.

Please let me know if you have any idea about this.


File upload was not working because I was usign it inside atlas update panel. If I use it outside then everything works fine.

Thursday, March 22, 2012

Object reference not set to an instance of an object.

Hello,

I am loading a simple rss file via the XmlTextReader
and getting the following error:

Object reference not set to an instance of an object.

Here is the code which I use:

CheckRSS("http://www.rubyxml.com/index.rb/rss")

private function CheckRSS(byval strRSS as string)
Dim reader as new XmlTextReader(strRSS)
Dim xmlDoc as new XmlDocument

Try
xmlDoc.Load(strRSS)
Catch ex As Exception
Response.Write("ERR in Rss File:" & strRSS
& "<br>")
Response.Write("Err: RSS File:" & ex.Message
& "<br>")
Exit Function
End Try

' load only the item nodes
Dim nodes As XmlNodeList = xmlDoc.SelectNodes
("/rss/channel/item")

For Each node As XmlNode In nodes
Try
Dim strPostTitle as string = node
("title").InnerXml
Dim strPost as string = node
("description").InnerXml
Dim strPostURL as string = node
("link").InnerXml
Dim strPostDate as string = node
("pubDate").InnerXml

response.write(strPostTitle & "<br>")
Catch ex As Exception
Response.Write("ERR in loading nodes: " &
ex.Message() & "<br>")
Exit Function
End Try
Next
end function

Can somebody tell me whats wrong with my code?

ThanksUr not assigning something!
Something is missing..
on What line was the exception code?

"Anonymous" wrote:

> Hello,
> I am loading a simple rss file via the XmlTextReader
> and getting the following error:
> Object reference not set to an instance of an object.
> Here is the code which I use:
> CheckRSS("http://www.rubyxml.com/index.rb/rss")
>
> private function CheckRSS(byval strRSS as string)
> Dim reader as new XmlTextReader(strRSS)
> Dim xmlDoc as new XmlDocument
> Try
> xmlDoc.Load(strRSS)
> Catch ex As Exception
> Response.Write("ERR in Rss File:" & strRSS
> & "<br>")
> Response.Write("Err: RSS File:" & ex.Message
> & "<br>")
> Exit Function
> End Try
> ' load only the item nodes
> Dim nodes As XmlNodeList = xmlDoc.SelectNodes
> ("/rss/channel/item")
> For Each node As XmlNode In nodes
> Try
> Dim strPostTitle as string = node
> ("title").InnerXml
> Dim strPost as string = node
> ("description").InnerXml
> Dim strPostURL as string = node
> ("link").InnerXml
> Dim strPostDate as string = node
> ("pubDate").InnerXml
> response.write(strPostTitle & "<br>")
> Catch ex As Exception
> Response.Write("ERR in loading nodes: " &
> ex.Message() & "<br>")
> Exit Function
> End Try
> Next
> end function
> Can somebody tell me whats wrong with my code?
> Thanks
>
> Can somebody tell me whats wrong with my code?

Let me count the ways...

To start with, your business logic and interface code are involved in an
unholy union. Didn't you hear about the Great Divorce that ASP.Net was
intended to provoke, between business logic and interface?

It would also help if you pointed out which ine threw the exception. If
you're going to suppress exceptions with a Try/Catch, you could at least
write the stack trace out so you could see where the exception occurred. The
exception message indicates that your code attempted to reference an object
that was not instantiated (Nothing). You didn't post ALL the code you used.
Are you sure the exception came from this block of code, or the calling
code? The reason I ask is that you have defined a function that returns a
string, but if an exception occurs, it calls "Exit Function" which returns
Nothing. If the calling code tried to treat Nothing like a string, that
would throw that particular exception.

Other than that, there are severl places where you might have referenced a
null object (Nothing, for you programmers from Rio Linda), but didn't check
for Nothing prior to the reference, so it could be any of those places.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Anonymous" <anonymous@.discussions.microsoft.com> wrote in message
news:570001c4c835$43807350$a601280a@.phx.gbl...
> Hello,
> I am loading a simple rss file via the XmlTextReader
> and getting the following error:
> Object reference not set to an instance of an object.
> Here is the code which I use:
> CheckRSS("http://www.rubyxml.com/index.rb/rss")
>
> private function CheckRSS(byval strRSS as string)
> Dim reader as new XmlTextReader(strRSS)
> Dim xmlDoc as new XmlDocument
> Try
> xmlDoc.Load(strRSS)
> Catch ex As Exception
> Response.Write("ERR in Rss File:" & strRSS
> & "<br>")
> Response.Write("Err: RSS File:" & ex.Message
> & "<br>")
> Exit Function
> End Try
> ' load only the item nodes
> Dim nodes As XmlNodeList = xmlDoc.SelectNodes
> ("/rss/channel/item")
> For Each node As XmlNode In nodes
> Try
> Dim strPostTitle as string = node
> ("title").InnerXml
> Dim strPost as string = node
> ("description").InnerXml
> Dim strPostURL as string = node
> ("link").InnerXml
> Dim strPostDate as string = node
> ("pubDate").InnerXml
> response.write(strPostTitle & "<br>")
> Catch ex As Exception
> Response.Write("ERR in loading nodes: " &
> ex.Message() & "<br>")
> Exit Function
> End Try
> Next
> end function
> Can somebody tell me whats wrong with my code?
> Thanks

Friday, March 16, 2012

Object reference not set to an instance of an object.

Hello,
I am loading a simple rss file via the XmlTextReader
and getting the following error:
Object reference not set to an instance of an object.
Here is the code which I use:
CheckRSS("http://www.rubyxml.com/index.rb/rss")
private function CheckRSS(byval strRSS as string)
Dim reader as new XmlTextReader(strRSS)
Dim xmlDoc as new XmlDocument
Try
xmlDoc.Load(strRSS)
Catch ex As Exception
Response.Write("ERR in Rss File:" & strRSS
& "<br>")
Response.Write("Err: RSS File:" & ex.Message
& "<br>")
Exit Function
End Try
' load only the item nodes
Dim nodes As XmlNodeList = xmlDoc.SelectNodes
("/rss/channel/item")
For Each node As XmlNode In nodes
Try
Dim strPostTitle as string = node
("title").InnerXml
Dim strPost as string = node
("description").InnerXml
Dim strPostURL as string = node
("link").InnerXml
Dim strPostDate as string = node
("pubDate").InnerXml
response.write(strPostTitle & "<br>")
Catch ex As Exception
Response.Write("ERR in loading nodes: " &
ex.Message() & "<br>")
Exit Function
End Try
Next
end function
Can somebody tell me whats wrong with my code?
ThanksUr not assigning something!
Something is missing..
on What line was the exception code?
"Anonymous" wrote:

> Hello,
> I am loading a simple rss file via the XmlTextReader
> and getting the following error:
> Object reference not set to an instance of an object.
> Here is the code which I use:
> CheckRSS("http://www.rubyxml.com/index.rb/rss")
>
> private function CheckRSS(byval strRSS as string)
> Dim reader as new XmlTextReader(strRSS)
> Dim xmlDoc as new XmlDocument
> Try
> xmlDoc.Load(strRSS)
> Catch ex As Exception
> Response.Write("ERR in Rss File:" & strRSS
> & "<br>")
> Response.Write("Err: RSS File:" & ex.Message
> & "<br>")
> Exit Function
> End Try
> ' load only the item nodes
> Dim nodes As XmlNodeList = xmlDoc.SelectNodes
> ("/rss/channel/item")
> For Each node As XmlNode In nodes
> Try
> Dim strPostTitle as string = node
> ("title").InnerXml
> Dim strPost as string = node
> ("description").InnerXml
> Dim strPostURL as string = node
> ("link").InnerXml
> Dim strPostDate as string = node
> ("pubDate").InnerXml
> response.write(strPostTitle & "<br>")
> Catch ex As Exception
> Response.Write("ERR in loading nodes: " &
> ex.Message() & "<br>")
> Exit Function
> End Try
> Next
> end function
> Can somebody tell me whats wrong with my code?
> Thanks
>
> Can somebody tell me whats wrong with my code?
Let me count the ways...
To start with, your business logic and interface code are involved in an
unholy union. Didn't you hear about the Great Divorce that ASP.Net was
intended to provoke, between business logic and interface?
It would also help if you pointed out which ine threw the exception. If
you're going to suppress exceptions with a Try/Catch, you could at least
write the stack trace out so you could see where the exception occurred. The
exception message indicates that your code attempted to reference an object
that was not instantiated (Nothing). You didn't post ALL the code you used.
Are you sure the exception came from this block of code, or the calling
code? The reason I ask is that you have defined a function that returns a
string, but if an exception occurs, it calls "Exit Function" which returns
Nothing. If the calling code tried to treat Nothing like a string, that
would throw that particular exception.
Other than that, there are severl places where you might have referenced a
null object (Nothing, for you programmers from Rio Linda), but didn't check
for Nothing prior to the reference, so it could be any of those places.
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
"Anonymous" <anonymous@.discussions.microsoft.com> wrote in message
news:570001c4c835$43807350$a601280a@.phx.gbl...
> Hello,
> I am loading a simple rss file via the XmlTextReader
> and getting the following error:
> Object reference not set to an instance of an object.
> Here is the code which I use:
> CheckRSS("http://www.rubyxml.com/index.rb/rss")
>
> private function CheckRSS(byval strRSS as string)
> Dim reader as new XmlTextReader(strRSS)
> Dim xmlDoc as new XmlDocument
> Try
> xmlDoc.Load(strRSS)
> Catch ex As Exception
> Response.Write("ERR in Rss File:" & strRSS
> & "<br>")
> Response.Write("Err: RSS File:" & ex.Message
> & "<br>")
> Exit Function
> End Try
> ' load only the item nodes
> Dim nodes As XmlNodeList = xmlDoc.SelectNodes
> ("/rss/channel/item")
> For Each node As XmlNode In nodes
> Try
> Dim strPostTitle as string = node
> ("title").InnerXml
> Dim strPost as string = node
> ("description").InnerXml
> Dim strPostURL as string = node
> ("link").InnerXml
> Dim strPostDate as string = node
> ("pubDate").InnerXml
> response.write(strPostTitle & "<br>")
> Catch ex As Exception
> Response.Write("ERR in loading nodes: " &
> ex.Message() & "<br>")
> Exit Function
> End Try
> Next
> end function
> Can somebody tell me whats wrong with my code?
> Thanks
>