Click here to Skip to main content
15,886,781 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If have a user control with a textbox. I instantiate this usercontrol on an aspx page.

Now the page load event looks like this:

C#
protected void Page_Load(object sender, EventArgs e)
       {
           TrialControl tc = new TrialControl(); //This is my Usercontrol

           Label labelUctext = (Label)(tc.FindControl("labelText1"));
           if (labelUctext != null)
           {
               if (labelUctext.Text != String.Empty)
               {
                   labelText.Text = labelUctext.Text;
               }
           }
       }


Here labelUctext always holds NULL. thus it is not able to find the inner label. Extremely basic question, but what am I doing wrong?
Posted

add this method into your usercontrol.cs and call this method
like this
string str=usercontrol.AddProperty;


C#
public string AddProperty
    {
        get
        {
            return labelText1.Text;
        }
        set
        {
            labelText1.Text = value;
        }
    }
 
Share this answer
 
Comments
sameerkulkarni777 10-Jul-13 8:23am    
@Neeraj, Nope man. Now at runtime it points to labelText1.text inside the property 'AddProperty', saying

'Object reference not set to an instance of an object'
foreach (GridViewRow gr in grdroomavail.Rows)
{
(Literal)tt=((Literal)gr.FindControl("ltrroom") as Literal).Text
}
 
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