Inheritance Error!!! Need help so much

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

Marina

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.
 
H

Hai Nguyen

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

Thanks
 
M

Marina

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

Hai Nguyen

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top