2

I have register a page using the code

<%@ Register TagPrefix="uc1" TagName="side" Src="side.ascx" %>

And called this by using the code

<uc1:side ID="Side1" runat="server"></uc1:side>

And i tried to acces the ID="Side1" in behind by using

private void Page_Load(object sender, System.EventArgs e)
{
    // Put user code to initialize the page here

    if (Session["UName"] != null || Session["UName"] != " ")
    {
        Side1.Visible = true;
    }
    else
        Side1.Visible = true;
    }

but gives the error

The name 'Side1' does not exist in the current context .

How will i resolve it by accessing the 'id' using 'protected System.Web.UI'.

zed
  • 2,298
  • 4
  • 27
  • 44

1 Answers1

0

Check the access modifier on your WebUserControl partial class definition (ie YourControl.ascx.cs file), it should be something like this:

public partial class SideControl : System.Web.UI.UserControl
{
    // your code...
}

You can find more information about access modifiers here.

Community
  • 1
  • 1
zed
  • 2,298
  • 4
  • 27
  • 44
  • Thanks a lot for helping me –  Jul 31 '15 at 06:10
  • By using above i modified the code like this ' protected System.Web.UI.HtmlControls.HtmlGenericControl head; private void Page_Load(object sender, System.EventArgs e) { if (Session["UName"] != null) { head.Controls.Add(this.LoadControl("header.ascx")); }' –  Aug 03 '15 at 11:00