473,757 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Composite control with dynamic composite controls

Hello,

I'm building a web application that will build a dynamic form based
upon questions in a database. This form will have several different
sections that consist of a panel containing one to many questions.

To keep it simple, I'll describe the basics of what I'm trying to
design.

I've created a TextBox composite control that consists of a label for
the question being asked, and a textbox for the input. (There's
validation as well, but I'm keeping this down to basics.)

I've also created a Panel composite control that consists of a label
for the header and the panel which will act as the container for the
questions that will be asked.

I've created a method in the Panel control that gets the questions
from the database and dynamically adds the new Composite TextBox
control to the Panel Controls Collection.

I've tried the following:

1) I've called this method from within CreateChildCont rols to try and
recreate the the dynamic controls since Controls.Clear( ) is called at
the top of this method anytime EnsureChild controls is called, but
this is not working properly.
2) I've called this method from the Render method which renders the
composite controls fine, but this doesn't seem like the proper place
to call this method from either, and this is also problematic.
3) Beat head on wall, tried many other panic tactics, but all I have
now is a headache.

Problem is, I can't see any of the dynamically created controls in the
Panel's controls collection so that I can get the values back out of
them upon submit.

Any help is appreciated.
Thanks.
using System;
using System.Componen tModel;
using System.Componen tModel.Design;
using System.Data;
using System.Data.Sql Client;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.W ebControls;
[assembly:TagPre fix("MYControls .ServerControls ", "MYControls ")]

namespace MYControls.Serv erControls
{

public class ccPanel : WebControl, INamingContaine r
{
#region Page Controls Declaration

private string sCon = "server=somerse rver;database=s omedbase;User
ID=auser;pwd=ap assword";
private System.Data.Sql Client.SqlConne ction con = new
SqlConnection() ;

private Panel _pnlContainer;
private Label _lblHeader;

private string m_SectionCd;
private int m_InstitutionID ;

private string LabelCssClass = "FieldLabel ";
private string TextBoxCssClass = "TextBoxTreatme nt";

#endregion

#region Properties delegated to child controls
[
Bindable(false) ,
Category("Appea rance"),
DefaultValue("" ),
Description("Th e Section of this panel for the application")
]
public string FormSectionCd
{
get
{
return m_SectionCd;
}
set
{
m_SectionCd = value;

}
}

[
Bindable(false) ,
Category("Appea rance"),
DefaultValue("" ),
Description("Th e InstitutionID for this application")
]
public int FormInstitution ID
{
get
{
return m_InstitutionID ;
}
set
{
m_InstitutionID = value;
}
}

#endregion Properties delegated to child controls

#region Overriden methods
protected override void CreateChildCont rols()
{
Controls.Clear( );

this._lblHeader = new Label();
this._lblHeader .Text = "Test Label";
this._lblHeader .CssClass = LabelCssClass;

this._pnlContai ner = new Panel();
this._pnlContai ner.CssClass = TextBoxCssClass ;
this._pnlContai ner.ID = "TestPanel" ;
this._pnlContai ner.Width = Unit.Pixel(500) ;

this.Controls.A dd(this._lblHea der);
this.Controls.A dd(this._pnlCon tainer);
}

/// <summary>
/// Method that actually renders the control in a nicely formatted
table.
/// </summary>
/// <param name="writer">H tmlTextWriter</param>
protected override void Render(HtmlText Writer writer)
{
//The beginning of the dynamic form building.
this.CreateIt() ;

AddAttributesTo Render(writer);

writer.AddAttri bute(HtmlTextWr iterAttribute.W idth, "500");
writer.AddAttri bute(HtmlTextWr iterAttribute.C lass,this.m_Tab leCssClass);
writer.AddAttri bute(HtmlTextWr iterAttribute.C ellpadding,this .m_TableCellpad ding.ToString() );
writer.AddAttri bute(HtmlTextWr iterAttribute.C ellspacing,this .m_TableCellspa cing.ToString() );
writer.RenderBe ginTag(HtmlText WriterTag.Table );
writer.RenderBe ginTag(HtmlText WriterTag.Tr);

writer.AddAttri bute(HtmlTextWr iterAttribute.A lign, "left");
writer.RenderBe ginTag(HtmlText WriterTag.Td);
this._lblHeader .RenderControl( writer);
writer.RenderEn dTag(); // Td
writer.RenderEn dTag(); // Tr

writer.RenderBe ginTag(HtmlText WriterTag.Tr);
writer.RenderBe ginTag(HtmlText WriterTag.Td);
this._pnlContai ner.RenderContr ol(writer);
writer.RenderEn dTag(); // Td

writer.RenderEn dTag(); // Tr
writer.RenderEn dTag(); // Table

con.Close();
}
#endregion Overriden methods

private void CreateIt()
{
string SectionName = this.GetSection Name();
this._lblHeader .Text = SectionName;
DataSet ds = this.GetSection Questions();

if (ds.Tables["Questions"].Rows.Count == 0)
{
// this._pnlContai ner.Visible = false;
this._lblHeader .Text += " ----- No Questions. This is INVISIBLE";
}
else
{
foreach (DataRow dr in ds.Tables["Questions"].Rows)
{
switch (dr["QuestionTypeCd "].ToString().ToL ower())
{
case "tb":
this.CreateCCTe xtBox(dr);
break;
}
}
}
}

private void CreateCCTextBox (DataRow dr)
{
ccTextBox ccTextBox = new ccTextBox();
ccTextBox.Field TBID = dr["FieldName"].ToString();
ccTextBox.Field TBCssClass = this.TextBoxCss Class;
ccTextBox.Field LBL = dr["Question"].ToString();
ccTextBox.Field LBLCssClass = this.LabelCssCl ass;

this._pnlContai ner.Controls.Ad d(ccTextBox);
}

private DataSet GetSectionQuest ions()
{
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter( "sp_GetQuestion s_ForForm",
con);
da.SelectComman d.CommandType = CommandType.Sto redProcedure;

da.SelectComman d.Parameters.Ad d("@Institution ID", SqlDbType.Int);
da.SelectComman d.Parameters["@InstitutionID "].Value =
this.m_Institut ionID;

da.SelectComman d.Parameters.Ad d("@SectionCd ",
SqlDbType.VarCh ar,250);
da.SelectComman d.Parameters["@SectionCd "].Value =
"PRQ";//this.m_SectionC d;

da.Fill(ds, "Questions" );
da.Dispose();

return ds;
}

private string GetSectionName( )
{
con.ConnectionS tring = sCon;
con.Open();

SqlCommand cmd = new SqlCommand("sp_ GetSectionName" , con);
cmd.CommandType = CommandType.Sto redProcedure;

cmd.Parameters. Add("@SectionCd ", SqlDbType.VarCh ar);
cmd.Parameters["@SectionCd "].Value = this.m_SectionC d;

SqlParameter SectionName = cmd.Parameters. Add("@SectionNa me",
SqlDbType.VarCh ar, 250);
SectionName.Dir ection = ParameterDirect ion.Output;

cmd.ExecuteNonQ uery();

string Name = cmd.Parameters["@SectionNa me"].Value.ToString ();

cmd.Dispose();
return Name;
}

#region Overriden properties
public override ControlCollecti on Controls
{
get
{
EnsureChildCont rols();
return base.Controls;
}
}
#endregion Overriden properties

}
}
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 18 '05 #1
1 3151
Issue solved.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2321
by: dx | last post by:
I have the Microsoft Press: Developing Microsoft ASP.NET Server Controls and Components book. It's starting to shine some light on control development but there is something about composite controls that I don't understand... I've included a snippet from Chapter 12 below on Composite Controls: <start> Override the CreateChildControls method to instantiate child controls, initialize them, and add them to the control tree. Do not perform...
2
1850
by: Harry | last post by:
Hello, I have a composite WebControl that I'm dynamically instantiating at runtime using Reflection. When I create a new instance of my control I immediately iterate through it's child control collection (it has about 4 child controls). The problem is none of these controls are loaded or accessible when I create the instance since, I believe, they are created by the server at a later point in time. How could I force my composite control...
3
2562
by: Martin | last post by:
Hi, I have created a composite control that has a number of standard asp.net controls on it that can themselves cause postbacks. What i need to do in my composite control is to determine which consituent control caused a postback. for example a have a consituent controls with two buttons on it "button1" and "button2" I have registered my control for postbacks using
4
4089
by: Mark Olbert | last post by:
This involves a family of related, databound ASPNET2 composite controls. I've managed to arrange things so that the composite controls restore themselves from ViewState on postback after they're initially configured during DataBind(). Thanks to Steven Cheng for pointing out that you have to set the constituent control properties after you add them to the composite control collection for the restore to work! However, I now have a...
3
3005
by: Beavis | last post by:
I hate to repost a message, but I am still at the same point where I was when I originally posted, and hopefully someone else will see this one... Ok, so I have gone off and documented the lifecycle of a page with a custom composite control on it. You can find that document here: http://www.ats-engineers.com/lifecycle.htm
6
2632
by: shapper | last post by:
Hello, I am working in a class library with various custom controls. In which cases should a control inherit Control, WebControl and CompositeControl classes? And when should a custom control implement INamingContainer? In this moment I am working on a custom control that is composed by a
0
10069
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9904
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9735
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8736
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7285
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3828
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2697
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.