Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Hi,
I have a Aspx page and a ascx page. And in aspx page I have radTabstrip and in each RadTb I am using Ascx.
I want to dynamically load the controls of ascx page in aspx page.
It is not able to find the controls of ascx once after aspx page is done if I again try to assign value to those ascx controls in ascx.cs page.
It says for the controls like label:

"Object reference not set to an instance of an object"

ASCX code:
protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            bindControls();

        }public void bindControls()
    {
//setting controlls values
lbl.text=some value;
    }

         
   }


ASpx Code:

HTML
protected voidGridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
//calling the ascx method
acsxpage objacsxpage=new acsxpage(); 
objacsxpage.bindControls();
}

Here it is not fininding the control lbl.


Thanks,
Please help to resolve this issue.
Posted
Updated 28-Sep-11 2:06am
v7
Comments
jim lahey 28-Sep-11 6:14am    
You need to show us some code if you want help with this.
veershilpa 28-Sep-11 6:30am    
ASCX code:
protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
bindControls();

}
public void bindControls()
{
//setting controlls values
lbl.text=some value;
}


}


ASpx Code:

protected voidGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
//calling the ascx method
acsxpage objacsxpage=new acsxpage();
objacsxpage.bindControls();
}

here it is not fininding the control lbl

I think you are creating new user controls instead of finding the usercontrols from RadTab or from whatever container you are using.

C#
acsxpage objacsxpage=new acsxpage(); 


Instead of the above code you have to access the instance which is already initialized in the aspx page.
 
Share this answer
 
v2
It can't find it, because it has no direct access to it.

Think about it: if you use this control on a different ASPX page, it will not have a lbl control. What is the control supposed to do then?

Find a better solution, or pass the lbl instance through to the ASCX control method instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900