PC Review


Reply
Thread Tools Rate Thread

Dynamic Loading of a User Control

 
 
=?Utf-8?B?RGFubnk=?=
Guest
Posts: n/a
 
      23rd Dec 2005
Hi,

I've create a usercontrol with a Calendar Control and a Textbox. The
SelectionChanged event of the calendar populates the textbox with the
selected date.



Also, I've created an aspx page with an ASP Table on the page.



Finally, I have class called PageControls.cs, where I generate cells for the
table on the aspx page.

These cells contain different html and asp controls. Now, I want to add my
usercontrol to one of the cells as well. But I keep on getting errors in
doing so. Is there someone that can please assist?



Here are code extracts to do the above mentioned.



=========================================

//file: MyUserControlCollection.ascx.cs

=========================================



public class DateBox : System.Web.UI.UserControl

{



protected System.Web.UI.WebControls.Calendar oCalendar;

protected System.Web.UI.WebControls.TextBox oDateBox;





private void Page_Load(object sender, System.EventArgs e)

{



}



#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

InitializeComponent();

base.OnInit(e);

}



private void InitializeComponent()

{

this.oCalendar.SelectionChanged += new
System.EventHandler(this.oCalendar_SelectionChanged);



}

#endregion



private void oCalendar_SelectionChanged(object sender,
System.EventArgs e)

{

oDateBox.Text = oCalendar.SelectedDate.ToString("dd
MMMM yyyy");

}

}





=======================

//file: TestForm.aspx

=======================



public class TestForm : System.Web.UI.Page

{

protected System.Web.UI.WebControls.Table Table1;



private void Page_Load(object sender, System.EventArgs e)

{

MyUtils.ControlUtils oUtils = new
MyUtils.ControlUtils();

oUtils.PopulateTable(ref Table1);

}



#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

InitializeComponent();

base.OnInit(e);

}



private void InitializeComponent()

{

this.Load += new System.EventHandler(this.Page_Load);



}

#endregion

}







=====================

//file: TestForm.cs

=====================



public class ControlUtils

{

public ControlUtils()

{



}





public void PopulateTable(ref System.Web.UI.WebControls.Table
oFormTable)

{

//Variables

TableRow oRow = new TableRow();

TableCell oCell = new TableCell();

Control oControl = new Control();



// Create DateBox object

MyUserControlCollection.DateBox oControl = new
MyUserControlCollection.DateBox();

oControl.EnableViewState=true;

oControl.Visible=true;



// Add Control To Cell

oCell.Width=Unit.Percentage(100);

oCell.Controls.Add(oControl);



//Add Cell to Row object

oRow.Cells.Add(oCell);



//Add Row to tabe from aspx Form

oFormTable.Rows.Add(oRow);



}

}


Regards
Danny


 
Reply With Quote
 
 
 
 
=?Utf-8?B?U2FsZWg=?=
Guest
Posts: n/a
 
      24th Dec 2005
you can use place holder to load your control in it..
--
regards,


"Danny" wrote:

> Hi,
>
> I've create a usercontrol with a Calendar Control and a Textbox. The
> SelectionChanged event of the calendar populates the textbox with the
> selected date.
>
>
>
> Also, I've created an aspx page with an ASP Table on the page.
>
>
>
> Finally, I have class called PageControls.cs, where I generate cells for the
> table on the aspx page.
>
> These cells contain different html and asp controls. Now, I want to add my
> usercontrol to one of the cells as well. But I keep on getting errors in
> doing so. Is there someone that can please assist?
>
>
>
> Here are code extracts to do the above mentioned.
>
>
>
> =========================================
>
> //file: MyUserControlCollection.ascx.cs
>
> =========================================
>
>
>
> public class DateBox : System.Web.UI.UserControl
>
> {
>
>
>
> protected System.Web.UI.WebControls.Calendar oCalendar;
>
> protected System.Web.UI.WebControls.TextBox oDateBox;
>
>
>
>
>
> private void Page_Load(object sender, System.EventArgs e)
>
> {
>
>
>
> }
>
>
>
> #region Web Form Designer generated code
>
> override protected void OnInit(EventArgs e)
>
> {
>
> InitializeComponent();
>
> base.OnInit(e);
>
> }
>
>
>
> private void InitializeComponent()
>
> {
>
> this.oCalendar.SelectionChanged += new
> System.EventHandler(this.oCalendar_SelectionChanged);
>
>
>
> }
>
> #endregion
>
>
>
> private void oCalendar_SelectionChanged(object sender,
> System.EventArgs e)
>
> {
>
> oDateBox.Text = oCalendar.SelectedDate.ToString("dd
> MMMM yyyy");
>
> }
>
> }
>
>
>
>
>
> =======================
>
> //file: TestForm.aspx
>
> =======================
>
>
>
> public class TestForm : System.Web.UI.Page
>
> {
>
> protected System.Web.UI.WebControls.Table Table1;
>
>
>
> private void Page_Load(object sender, System.EventArgs e)
>
> {
>
> MyUtils.ControlUtils oUtils = new
> MyUtils.ControlUtils();
>
> oUtils.PopulateTable(ref Table1);
>
> }
>
>
>
> #region Web Form Designer generated code
>
> override protected void OnInit(EventArgs e)
>
> {
>
> InitializeComponent();
>
> base.OnInit(e);
>
> }
>
>
>
> private void InitializeComponent()
>
> {
>
> this.Load += new System.EventHandler(this.Page_Load);
>
>
>
> }
>
> #endregion
>
> }
>
>
>
>
>
>
>
> =====================
>
> //file: TestForm.cs
>
> =====================
>
>
>
> public class ControlUtils
>
> {
>
> public ControlUtils()
>
> {
>
>
>
> }
>
>
>
>
>
> public void PopulateTable(ref System.Web.UI.WebControls.Table
> oFormTable)
>
> {
>
> //Variables
>
> TableRow oRow = new TableRow();
>
> TableCell oCell = new TableCell();
>
> Control oControl = new Control();
>
>
>
> // Create DateBox object
>
> MyUserControlCollection.DateBox oControl = new
> MyUserControlCollection.DateBox();
>
> oControl.EnableViewState=true;
>
> oControl.Visible=true;
>
>
>
> // Add Control To Cell
>
> oCell.Width=Unit.Percentage(100);
>
> oCell.Controls.Add(oControl);
>
>
>
> //Add Cell to Row object
>
> oRow.Cells.Add(oCell);
>
>
>
> //Add Row to tabe from aspx Form
>
> oFormTable.Rows.Add(oRow);
>
>
>
> }
>
> }
>
>
> Regards
> Danny
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
placement of dynamic control depends on VALUE of dynamic control Larry Bud Microsoft ASP .NET 1 10th Jan 2007 11:07 PM
Loading Dynamic User Control Error: "The control must be placed inside a form tag with runat=server" Help Please Second time posting. davidr@sharpesoft.com Microsoft ASP .NET 0 31st Aug 2006 06:26 PM
Showing a WaitDialog user control while another user control is loading BobRoyAce Microsoft Dot NET Framework Forms 0 20th Jul 2006 04:38 AM
Dynamic control array loading, can't unload control/replace with o =?Utf-8?B?Y2luZHk=?= Microsoft ASP .NET 2 8th Jun 2005 04:54 AM
Dynamic Events from Dynamic Controls on a User Control - Guess What? Broken! mytestemailaccount@gmail.com Microsoft ASP .NET 5 23rd Mar 2005 06:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:48 AM.