c# - UserControl working in one page but not in others -


I have already introduced this problem. I have to face the same type of problem again. I have a user control that shows information from some business object. I'm already using it on two pages. In both pages I use a method with a business object On the properties of the call, the control of the user control is called (mostly asp label). I call this method in the loaded method of aspx page.

  Secure Zero Page_load complete (Object Sender, EventArgs e) {control.LoadData (bussinessObject); }  

This is working fine on both pages. Now I have a third page where I am using the same control. Now when I call LoadData in this new page, I get an exception nullreference :

  object reference object Not set for an example. Description: An uncontrolled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where the code has originated from it. Exception Description: System.NullReferenceException: Object references are not set to an instance of an object source error: line 91: lblOrgName.Text = obj.Name;  

Edit: lblOrgName is NULL :( Please help me!

EDIT 2: I stepped through the code. Is called the page page and then the page load of the problem control is called.Continue on the closed brace () of the page load function, I have typed lblOrgName in the instant window and it appears to be zero: (

Then the page ended with the complete end of the load in user control And typed the name of the control in the instant window, it displays all the labels and other controls in the form of zero.

Edit 3:

I have a Protected Maker As mentioned in the reply in UserControl:

  protected OrgInfo () {}  

I am getting this error now:

  Compiler Error Message: CS0122: 'Controls.OrgInfo.OrgInfo ()' is inaccessible due to its security level.  

ASPX page In the root directory of the project and in the OrgInfo control control folder.

EDI T4:

I tried to make all the controls (mostly the label) in the page load method, but the control Counties count is 0 (zero)!

How can you put your user control over the page? It has happened in the past with me and the reason was that the control was added to the server as a control, not user control. All subcontrols in control were instatiated anytime.

You can see this by putting a protected default constructor in the code-behind code for user control:

protected MyUserControl () {}

this way Control can not be done immediately as a server control.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -