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?
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.
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 (
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.
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.
gstroud12
Member
10 Points
2 Posts
System.Web.UI.UserControl scope question
Jun 06, 2006 01:51 PM|LINK
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 fieldsFields =
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
Caddre
All-Star
26581 Points
5308 Posts
Re: System.Web.UI.UserControl scope question
Jun 06, 2006 03:35 PM|LINK
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://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.iwebpartrow.aspx
Gift Peddie
gstroud12
Member
10 Points
2 Posts
Re: System.Web.UI.UserControl scope question
Jun 06, 2006 07:23 PM|LINK
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
Caddre
All-Star
26581 Points
5308 Posts
Re: System.Web.UI.UserControl scope question
Jun 06, 2006 07:53 PM|LINK
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.
http://msdn2.microsoft.com/en-us/library/ms366540(VS.80).aspx
Gift Peddie
Caddre
All-Star
26581 Points
5308 Posts
Re: System.Web.UI.UserControl scope question
Jun 06, 2006 08:00 PM|LINK
Gift Peddie
mbanavige
All-Star
130719 Points
14322 Posts
ASPInsiders
Moderator
MVP
Re: System.Web.UI.UserControl scope question
Jun 06, 2006 08:50 PM|LINK
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