Accessing User Controls

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • michael234
    New Member
    • Feb 2008
    • 4

    Accessing User Controls

    Hi All,

    Before i get into things I'm writing in C# using VS2003 with framework 1.1.

    I am having a problem accessing a user control in the code behind.

    I'm using the user control for some repetitive code and i need to access a public property.

    .aspx
    [code=asp]
    <%@ Register TagPrefix="uc" TagName="Activi ty" Src="includes\i nc_Activity.asc x" %>

    <uc:ACTIVITY id="Activity1" runat="server" src="blank.html "></uc:ACTIVITY>
    [/code]

    .aspx.cs
    [code=cpp]
    public class client : System.Web.UI.P age
    {
    protected ACTIVITY Activity1;
    //...

    private void Page_Load(objec t sender, System.EventArg s e)
    {
    Activity1.sPage = "Client";
    //...

    [/code]

    .ascx.cs
    [code=cpp]
    private string _sPage;
    public string sPage
    {
    get {
    return _sPage;
    }
    set {
    sPage = value;
    }
    }

    [/code]
    Error when compiling;

    The type or namespace name 'ACTIVITY' could not be found (are you missing a using directive or an assembly reference?)


    Any help would be much appreciated!
    Last edited by Frinavale; Feb 11 '08, 04:13 PM. Reason: Added Code Tags
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    I think this should have been under the .NET forum and not in C++ forum

    Raghuram

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      I am moving this to the .NET forum.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by michael234
        Hi All,

        Before i get into things I'm writing in C# using VS2003 with framework 1.1.

        I am having a problem accessing a user control in the code behind.

        I'm using the user control for some repetitive code and i need to access a public property.

        .aspx
        [code=asp]
        <%@ Register TagPrefix="uc" TagName="Activi ty" Src="includes\i nc_Activity.asc x" %>

        <uc:ACTIVITY id="Activity1" runat="server" src="blank.html "></uc:ACTIVITY>
        [/code]
        ...
        The type or namespace name 'ACTIVITY' could not be found (are you missing a using directive or an assembly reference?)


        Any help would be much appreciated!
        Hi there!

        When you register your user control:
        [code=asp]
        [code=asp]
        <%@ Register TagPrefix="uc" TagName="Activi ty" Src="includes\i nc_Activity.asc x" %>

        <uc:ACTIVITY id="Activity1" runat="server" src="blank.html "></uc:ACTIVITY>
        [/code]

        Make sure that your referencing the proper directory.
        For starters you should be using forward-slash "/" instead of back-slash "\" in your Src string:
        [code=asp]
        <%@ Register TagPrefix="uc" TagName="Activi ty" Src="includes/inc_Activity.as cx" %>

        <uc:ACTIVITY id="Activity1" runat="server" src="blank.html "></uc:ACTIVITY>
        [/code]

        Make sure that you have a directory in your project "includes".
        If need be refer to it using reference notation....eg:
        [code=asp]
        <%@ Register TagPrefix="uc" TagName="Activi ty" Src="~/includes/inc_Activity.as cx" %>

        <uc:ACTIVITY id="Activity1" runat="server" src="blank.html "></uc:ACTIVITY>
        [/code]


        Cheers!

        -Frinny

        Comment

        • michael234
          New Member
          • Feb 2008
          • 4

          #5
          Thanks for the response.

          I have changed the / as you recommended and i do have the folder structure setup.

          The user control does compile and run, the only problem i am having is accessing the public property from the code behind in the page that "includes" the user control.

          If you have any ideas why this may be happening or a direction i could look to it would be much appreciated!

          Cheers,
          Michael



          Originally posted by Frinavale
          Hi there!

          When you register your user control:
          [code=asp]
          [code=asp]
          <%@ Register TagPrefix="uc" TagName="Activi ty" Src="includes\i nc_Activity.asc x" %>

          <uc:ACTIVITY id="Activity1" runat="server" src="blank.html "></uc:ACTIVITY>
          [/code]

          Make sure that your referencing the proper directory.
          For starters you should be using forward-slash "/" instead of back-slash "\" in your Src string:
          [code=asp]
          <%@ Register TagPrefix="uc" TagName="Activi ty" Src="includes/inc_Activity.as cx" %>

          <uc:ACTIVITY id="Activity1" runat="server" src="blank.html "></uc:ACTIVITY>
          [/code]

          Make sure that you have a directory in your project "includes".
          If need be refer to it using reference notation....eg:
          [code=asp]
          <%@ Register TagPrefix="uc" TagName="Activi ty" Src="~/includes/inc_Activity.as cx" %>

          <uc:ACTIVITY id="Activity1" runat="server" src="blank.html "></uc:ACTIVITY>
          [/code]


          Cheers!

          -Frinny

          Comment

          • michael234
            New Member
            • Feb 2008
            • 4

            #6
            Hi Guys,

            I have found a work around for my problem. The purpose of my behind code reference needs was to find out what page was using the user control through the public property. I found that i can set the value of the property through the aspx page.

            Code:
            <uc:inc_Activity id="inc_Activity1" runat="server" src="blank.html" [B]sPage="Client"[/B]></uc:inc_Activity>
            in doing this i now have no need to reference the user control through the code behind.

            Cheers,
            Michael

            Comment

            Working...