VjSharp newbie

I am trying to create a simple form to upload a file - I keep getting the following error

Object reference not set to an instance of an object.

Here is a portion of the code

publicclass UploadDataRSextends System.Web.UI.Page

{

protected System.Web.UI.HtmlControls.HtmlInputFile File1;

protected System.Web.UI.HtmlControls.HtmlSelect sYear;

protected System.Web.UI.WebControls.Label Label3;

protected System.Web.UI.WebControls.Label output;

protected System.Web.UI.WebControls.Label Label1;

protected System.Web.UI.WebControls.Label output2;

protected System.Web.UI.HtmlControls.HtmlInputFile File4;

protected System.Web.UI.HtmlControls.HtmlInputButton Submit2;

protected System.Web.UI.WebControls.TextBox TextBox2;

protected System.Web.UI.HtmlControls.HtmlSelect sMonth;

privatevoid Page_Load(Object sender, System.EventArgs e)

{

// Put user code to initialize the page here

}

#region Web Form Designer generated code

protectedvoid OnInit(System.EventArgs e)

{//
// CODEGEN: This call is required by the ASP.NET Web Form Designer. Donot remove this.//
InitializeComponent();

super.OnInit(e);

}

privatevoid InitializeComponent()

{

this.TextBox2.add_TextChanged(new System.EventHandler(this.TextBox2_TextChanged) );

this.Submit2.add_ServerClick(new System.EventHandler(this.Submit2_ServerClick) );

this.add_Load(new System.EventHandler(this.Page_Load) );........>>>error on this line

}

// #endregion

privatevoid Submit2_ServerClick (Object sender, System.EventArgs e)

{

String strFullName = File4.get_PostedFile().get_FileName();

String strName, strFname="";

int intIndex = strFullName.lastIndexOf("\\");

strName = (intIndex != -1) ? strFullName.substring(intIndex+1) : strFullName;

if (!strName.equals(""))

{

strFname = "d:\\dev\\PM\\" + strName;

File1.get_PostedFile().SaveAs(strFname);

}

else

{

output.set_Text("<div align=center><h3>Error: please select a file for uploading first!</h3></div>");

return;

}

Any help is appreciated .. Thanks

[4851 byte] By [Nip] at [2008-2-3]
# 1
Hi,

Just to understand your scenario better.

Are you using Visual Studio 2003 or 2005 Beta1/2?

I tried a simple new web application which contains this.add_Load( new System.EventHandler(this.Page_Load) ); , and it works for me.

If you comment out the other two functions, does it still give error?

You might want to post this on http://forums.asp.net/ as well.

Thanks,

VarunGupta at 2007-9-9 > top of Msdn Tech,Visual J#,Visual J# General...