Inheritance Error!!! Need help so much

  • Thread starter Thread starter Hai Nguyen
  • Start date Start date
H

Hai Nguyen

Page 1:

private void Page_Load(object sender, System.EventArgs e)
{

if(!Page.IsPostBack)

{

//step1.Font.Bold = true;

StateList();

string clientIP1 = Request.UserHostAddress;


string strServername = Request.ServerVariables["SERVER_NAME"];

string strServerIP = Request.ServerVariables["LOCAL_ADDR"];

string strRemoteIP = Request.ServerVariables["REMOTE_ADDR"];

string[] str1 = Request.UserLanguages;

Response.Write(clientIP1+ "<br>");

Response.Write(strServername +"<br>");

Response.Write(strServerIP+"<br>");

Response.Write(strRemoteIP+"<br>");

for (int count = 0; count < str1.Length; count++)

{

Response.Write("User Language " + count +": " + str1[count] + "<br>");

}



}

}

IF I used this: Page 2: System.Web.UI.Page it's correct

but if i use this Page 2: Page 1 there is an error:

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 272: //Update the statebox used ArrayList above
Line 273: //statebox = new DropDownList();
Line 274: statebox.DataSource = StateList;
Line 275: statebox.DataBind();
Line 276: }
 
Looks like you have broken code in your Page1 code. Looks like there is a
problem with the databinding code. My guess would be that statebox does not
exist as a dropdownlist on Page2.
 
You're right just because dropdown list statebox does not need for page 2.
What should I do to get over ?

Thanks
 
There is no visual inheritance in .aspx pages. All that is being inherited
is the compiled code. You would need to place all the elements that Page1
references on Page2.

Alternatively, you should look into UserControls. That allows you to create
a control (which can consist of any UI elements you want) onto a page. Any
code that is part of the UserControl will run as well. So if the user
control has a button and you wrote a handler for it, when the button is
clicked the handler will run.

Hai Nguyen said:
You're right just because dropdown list statebox does not need for page 2.
What should I do to get over ?

Thanks

Hai Nguyen said:
Page 1:

private void Page_Load(object sender, System.EventArgs e)
{

if(!Page.IsPostBack)

{

//step1.Font.Bold = true;

StateList();

string clientIP1 = Request.UserHostAddress;


string strServername = Request.ServerVariables["SERVER_NAME"];

string strServerIP = Request.ServerVariables["LOCAL_ADDR"];

string strRemoteIP = Request.ServerVariables["REMOTE_ADDR"];

string[] str1 = Request.UserLanguages;

Response.Write(clientIP1+ "<br>");

Response.Write(strServername +"<br>");

Response.Write(strServerIP+"<br>");

Response.Write(strRemoteIP+"<br>");

for (int count = 0; count < str1.Length; count++)

{

Response.Write("User Language " + count +": " + str1[count] + "<br>");

}



}

}

IF I used this: Page 2: System.Web.UI.Page it's correct

but if i use this Page 2: Page 1 there is an error:

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 272: //Update the statebox used ArrayList above
Line 273: //statebox = new DropDownList();
Line 274: statebox.DataSource = StateList;
Line 275: statebox.DataBind();
Line 276: }
 
Hi Marina

Thank you so much for your help. I got it work now.

I would like to ask you another one that if .Dotnet supports mutilple
inheritances

Thanks


Marina said:
There is no visual inheritance in .aspx pages. All that is being inherited
is the compiled code. You would need to place all the elements that Page1
references on Page2.

Alternatively, you should look into UserControls. That allows you to create
a control (which can consist of any UI elements you want) onto a page. Any
code that is part of the UserControl will run as well. So if the user
control has a button and you wrote a handler for it, when the button is
clicked the handler will run.

Hai Nguyen said:
You're right just because dropdown list statebox does not need for page 2.
What should I do to get over ?

Thanks

Hai Nguyen said:
Page 1:

private void Page_Load(object sender, System.EventArgs e)
{

if(!Page.IsPostBack)

{

//step1.Font.Bold = true;

StateList();

string clientIP1 = Request.UserHostAddress;


string strServername = Request.ServerVariables["SERVER_NAME"];

string strServerIP = Request.ServerVariables["LOCAL_ADDR"];

string strRemoteIP = Request.ServerVariables["REMOTE_ADDR"];

string[] str1 = Request.UserLanguages;

Response.Write(clientIP1+ "<br>");

Response.Write(strServername +"<br>");

Response.Write(strServerIP+"<br>");

Response.Write(strRemoteIP+"<br>");

for (int count = 0; count < str1.Length; count++)

{

Response.Write("User Language " + count +": " + str1[count] + "<br>");

}



}

}

IF I used this: Page 2: System.Web.UI.Page it's correct

but if i use this Page 2: Page 1 there is an error:

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 272: //Update the statebox used ArrayList above
Line 273: //statebox = new DropDownList();
Line 274: statebox.DataSource = StateList;
Line 275: statebox.DataBind();
Line 276: }
 
Back
Top