ASP namespace strong type access for dynamically loaded user control

Discussion in 'ASP .Net' started by Greg James, Apr 7, 2008.

  1. Greg James

    Greg James Guest

    ASP namespace strong type access for dynamically loaded user control
    (web application, not web site)

    I have a user control in a web application which I dynamically load
    from an aspx page as follows:
    UserControl ctl = Page.LoadControl("./User Controls/
    MailForwardingGrid2.ascx") as UserControl;
    form1.Controls.Add(ctl);

    This works fine.

    I have added 2 properties to the user control and would like to load
    the strong type version of the user control in order to set the new

    parameters at runtime. I would like to do something like the
    following:
    ASP.usercontrols_MailForwardingGrid2_ascx ctrl =
    (ASP.usercontrols_MailForwardingGrid2_ascx)Page.LoadControl("./User

    Controls/MailForwardingGrid2.ascx");
    ctrl.SourceTypeID = Int32.Parse(context);
    ctrl.SourceID = id;

    Unfortunately, the ASP namespace is not showing my user control (the
    ASP namespace is not showing up at all).

    I have tried "<%@ Register ... " and "<%@ Reference ... " to no avail
    as follows:


    <%@ Register Src="User Controls/MailForwardingGrid2.ascx"
    TagName="MailForwardingGrid2"
    TagPrefix="uc1" %>
    <%@ Reference Control="User Controls/MailForwardingGrid2.ascx" %>

    I access user controls through the ASP namespace from web sites all
    the time but the current failure is from a web application.

    Advice?


    -------------------------------------
    DETAILS:
    Here is the page from which I am attempting to access the user
    control...

    <%@ Page Language="C#" AutoEventWireup="true"
    CodeBehind="DisplayForm.aspx.cs"
    Inherits="WebApplication1.DisplayForm" %>

    <%@ Register Src="User Controls/MailForwardingGrid2.ascx"
    TagName="MailForwardingGrid2"
    TagPrefix="uc1" %>

    <%@ Reference Control="User Controls/MailForwardingGrid2.ascx" %>

    <%@ Register Assembly="DevExpress.Web.v8.1, Version=8.1.1.0,
    Culture=neutral, PublicKeyToken=9b171c9fd64da1d1"
    Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dxpc" %>

    <%@ Register Assembly="AjaxControlToolkit"
    Namespace="AjaxControlToolkit" TagPrefix="AjaxToolkit" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
    www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>

    </head>
    <body>
    <form id="form1" runat="server">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </form>
    </body>
    </html>

    Here is the body of the user control:
    namespace WebApplication1.User_Controls
    {

    public partial class MailForwardingGrid2 :
    System.Web.UI.UserControl
    {
    // NCR.Rads.MailForwarding.BusinessObjects.MailForwardInfoList
    infoList =

    NCR.Rads.MailForwarding.BusinessObjects.MailForwardInfoList.GetMailForwardInfoList(SourceContext,
    SourceId);
    MailForwardInfoList objList;

    protected void Page_Load(object sender, EventArgs e)
    {
    //objList = MailForwardInfoList.GetMailForwardInfoList(1,
    "p000196");
    objList =
    MailForwardInfoList.GetMailForwardInfoList(SourceTypeID, SourceID);
    gvMailForwardingTemplate.DataSource = objList;
    gvMailForwardingTemplate.KeyFieldName = "InvoiceId";
    gvMailForwardingTemplate.DataBind();
    }

    private int sourceTypeID;
    public int SourceTypeID
    {
    get { return sourceTypeID; }
    set { sourceTypeID = value; }
    }

    private string sourceID;
    public string SourceID
    {
    get { return sourceID; }
    set { sourceID = value; }
    }



    //
    //protected void CslaDataSource1_SelectMethod(object sender,
    Csla.Web.SelectObjectArgs e)
    //{
    // e.BusinessObject = objList;

    //}
    }
    Greg James, Apr 7, 2008
    #1
    1. Advertising

  2. Does the .ascx also have a codebehind? If so then use the namespace and
    classname defined in the codebehind for the user control.

    Hope this helps,
    Mark Fitzpatrick
    Microsoft MVP - Expression

    "Greg James" <> wrote in message
    news:...
    > ASP namespace strong type access for dynamically loaded user control
    > (web application, not web site)
    >
    > I have a user control in a web application which I dynamically load
    > from an aspx page as follows:
    > UserControl ctl = Page.LoadControl("./User Controls/
    > MailForwardingGrid2.ascx") as UserControl;
    > form1.Controls.Add(ctl);
    >
    > This works fine.
    >
    > I have added 2 properties to the user control and would like to load
    > the strong type version of the user control in order to set the new
    >
    > parameters at runtime. I would like to do something like the
    > following:
    > ASP.usercontrols_MailForwardingGrid2_ascx ctrl =
    > (ASP.usercontrols_MailForwardingGrid2_ascx)Page.LoadControl("./User
    >
    > Controls/MailForwardingGrid2.ascx");
    > ctrl.SourceTypeID = Int32.Parse(context);
    > ctrl.SourceID = id;
    >
    > Unfortunately, the ASP namespace is not showing my user control (the
    > ASP namespace is not showing up at all).
    >
    > I have tried "<%@ Register ... " and "<%@ Reference ... " to no avail
    > as follows:
    >
    >
    > <%@ Register Src="User Controls/MailForwardingGrid2.ascx"
    > TagName="MailForwardingGrid2"
    > TagPrefix="uc1" %>
    > <%@ Reference Control="User Controls/MailForwardingGrid2.ascx" %>
    >
    > I access user controls through the ASP namespace from web sites all
    > the time but the current failure is from a web application.
    >
    > Advice?
    >
    >
    > -------------------------------------
    > DETAILS:
    > Here is the page from which I am attempting to access the user
    > control...
    >
    > <%@ Page Language="C#" AutoEventWireup="true"
    > CodeBehind="DisplayForm.aspx.cs"
    > Inherits="WebApplication1.DisplayForm" %>
    >
    > <%@ Register Src="User Controls/MailForwardingGrid2.ascx"
    > TagName="MailForwardingGrid2"
    > TagPrefix="uc1" %>
    >
    > <%@ Reference Control="User Controls/MailForwardingGrid2.ascx" %>
    >
    > <%@ Register Assembly="DevExpress.Web.v8.1, Version=8.1.1.0,
    > Culture=neutral, PublicKeyToken=9b171c9fd64da1d1"
    > Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dxpc" %>
    >
    > <%@ Register Assembly="AjaxControlToolkit"
    > Namespace="AjaxControlToolkit" TagPrefix="AjaxToolkit" %>
    >
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
    > www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >
    > <html xmlns="http://www.w3.org/1999/xhtml" >
    > <head runat="server">
    > <title>Untitled Page</title>
    >
    > </head>
    > <body>
    > <form id="form1" runat="server">
    > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    > </form>
    > </body>
    > </html>
    >
    > Here is the body of the user control:
    > namespace WebApplication1.User_Controls
    > {
    >
    > public partial class MailForwardingGrid2 :
    > System.Web.UI.UserControl
    > {
    > // NCR.Rads.MailForwarding.BusinessObjects.MailForwardInfoList
    > infoList =
    >
    > NCR.Rads.MailForwarding.BusinessObjects.MailForwardInfoList.GetMailForwardInfoList(SourceContext,
    > SourceId);
    > MailForwardInfoList objList;
    >
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > //objList = MailForwardInfoList.GetMailForwardInfoList(1,
    > "p000196");
    > objList =
    > MailForwardInfoList.GetMailForwardInfoList(SourceTypeID, SourceID);
    > gvMailForwardingTemplate.DataSource = objList;
    > gvMailForwardingTemplate.KeyFieldName = "InvoiceId";
    > gvMailForwardingTemplate.DataBind();
    > }
    >
    > private int sourceTypeID;
    > public int SourceTypeID
    > {
    > get { return sourceTypeID; }
    > set { sourceTypeID = value; }
    > }
    >
    > private string sourceID;
    > public string SourceID
    > {
    > get { return sourceID; }
    > set { sourceID = value; }
    > }
    >
    >
    >
    > //
    > //protected void CslaDataSource1_SelectMethod(object sender,
    > Csla.Web.SelectObjectArgs e)
    > //{
    > // e.BusinessObject = objList;
    >
    > //}
    > }
    >
    Mark Fitzpatrick, Apr 7, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thanh Nguyen
    Replies:
    0
    Views:
    442
    Thanh Nguyen
    Apr 1, 2004
  2. Tonix
    Replies:
    0
    Views:
    418
    Tonix
    Aug 24, 2004
  3. namekuseijin

    Re: "Strong typing vs. strong testing"

    namekuseijin, Sep 27, 2010, in forum: C Programming
    Replies:
    214
    Views:
    3,341
    Nick Keighley
    Oct 17, 2010
  4. namekuseijin

    Re: "Strong typing vs. strong testing"

    namekuseijin, Sep 27, 2010, in forum: Python
    Replies:
    229
    Views:
    3,438
    Gregory Ewing
    Oct 29, 2010
  5. Greg James
    Replies:
    0
    Views:
    200
    Greg James
    Apr 7, 2008
Loading...

Share This Page