locked
System.Web.UI.UserControl scope question RRS feed

  • Question

  • User-532289929 posted

    I'm trying to create a framework that will dynamically create a request entry page.  The approach I'm taking uses two user controls: 1 the request page and two the rows (entry fields) that will make up the request and a class that will control the creation of the request. 

    The problem I'm having is I'm not able to reach the row  usercontrol within the controller class.

     

    For example my controller class looks like this:

    using System;

    using System.Data;

    using System.Configuration;

    using System.Web;

    using System.Web.Security;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using System.Web.UI.WebControls.WebParts;

    using System.Web.UI.HtmlControls;

    using ITClassLib;

    using ITClassLib.DataAccess;

    using System.Web.UI.UserControl;

     

    public class RequestController

    {

    Int32 _OID;

    CSSITArrayList Fields;

    public RequestController()

    {

    //

    // TODO: Add constructor logic here

    //

    }

    public void BuildRequest(Int32 ReqNo, PlaceHolder phFields, PlaceHolder phActionBtns)

    {

    _OID = ReqNo;

    //Populate fields

    Fields = RequestData.GetFields(_OID);

    foreach (RequestField field in Fields)

    {

    RequestRow oRow = phFields.Page.LoadControl("RequestRow.ascx");

    ....do something with oRow like add it to a container.

    }

    }

    public Int32 RequestNo

    {

    get

    {

    return _OID;

    }

    }

    }

     

    It complaining on the line that I try and create an instance of RequestRow.  It doesn't recognize RequestRow.  I'm missing something here.  I was thinking you could create and instance of a usercontrol within a class.  This there a using directive I'm missing?

     

    Thanks

     

    Greg

    Tuesday, June 6, 2006 9:51 AM

All replies

  • User1416329745 posted

    You are missing the IWebPartRow interface and I think the web control class also comes with a class you can use.  Try the link below for more and btw the Webpart class comes with about four or more interfaces you can use.  Hope this helps.

    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.iwebpartrow.aspx

    Tuesday, June 6, 2006 11:35 AM
  • User-532289929 posted

    Thanks for the quick reply, but webparts doesn't help me here.  I guessmy question is simply:  How can you load an instance of a user web control into a variable from a method in a method of an instance of a class?

    This code work if I place it in another user web control  where I've registered (

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

    ) RequestRow

    RequestRow oRow = (RequestRow)phFields.Page.LoadControl("RequestRow.ascx");

    oRow.setFieldLabelName(field.FieldName);

    phFields.Controls.Add(oRow);

     

    If I try and use this code in a class method it doesn't know where RequestRow resides.

     

    Greg

    Tuesday, June 6, 2006 3:23 PM
  • User1416329745 posted

    You need to implement all those interfaces to get what you want, IWebPartTable Interface, IWebPartField Interface and IWebPartRow Interface.  The reason is the Webpart class was created to provide more features in a user control.  Try the link below for an alternative.  Hope this helps.

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    http://msdn.microsoft.com/en-us/library/ms366540(VS.80).aspx

    Tuesday, June 6, 2006 3:53 PM
  • User1416329745 posted
    Why you need all those interfaces? The simple answer is a page is used to create a User control when last I checked it has no table or column which can give you a row.  Hope this helps.
    Tuesday, June 6, 2006 4:00 PM
  • User-158764254 posted

    if your using asp.net 2.0 read this: http://west-wind.com/weblog/posts/3016.aspx

    the new ASP.NET 2.0 dynamic compilation model is a problem if you need to explicitly cast dynamically loaded user controls.

    I havent tried it, but i believe that the Web Application Project uses a compilation model that support what you're trying to accomplish.

    Heres a couple links re: W.A.P.

    http://weblogs.asp.net/scottgu/archive/2006/05/08/445742.aspx
    http://msdn.microsoft.com/asp.net/reference/infrastructure/wap/default.aspx

    Tuesday, June 6, 2006 4:50 PM