469,909 Members | 1,572 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,909 developers. It's quick & easy.

get values from dynamically added user controls

I need help in getting the values from a dynamically added user control when a user submits a form. The controls are added to a placeholder and this all works fine - but its looping through the controls that i'm having trouble with.

Its the "case 1:" statement that i need help with

cheers in advance for any help

my code is as follows.

// a Property that manages a counter stored in ViewState
protected int NumberOfSchemeControls
{
get{return (int)ViewState["NumControls"];}
set{ViewState["NumControls"] = value;}
}

if(!Page.IsPostBack)
//Initiate the counter of dynamically added scheme controls
this.NumberOfSchemeControls = 0;
else
//Scheme Controls must be repeatedly be created on postback
this.createSchemeControls();


private void createSchemeControls()
{
int count = this.NumberOfSchemeControls;

for(int i = 0; i < count; i++)
{
scheme uc = (scheme) this.Page.LoadControl("scheme.ascx");
uc.ID = "ControlID_" + i.ToString();
//Add the Controls to the container of your choice
PlaceHolder1.Controls.Add(uc);
}
}

private void addSchemeControl()
{
scheme uc = (scheme) this.Page.LoadControl("scheme.ascx");
uc.ID = "ControlID_" + NumberOfSchemeControls.ToString();

PlaceHolder1.Controls.Add(uc);
this.NumberOfSchemeControls++;
}


private void bntMoreSchemes_Click(object sender, System.EventArgs e)
{
this.addSchemeControl();
}


private void btnSend_Click(object sender, System.EventArgs e)
{
try
{
user = Opra.piano.HelperClasses.UserHelper.GetUser(User.I dentity.Name);
MailMessage mail = new MailMessage();
mail.To = "james.burnage@someDomain.com";
mail.Cc = user.Email;
mail.Subject = "Basic search request submission";
mail.From = user.Email;
mail.BodyFormat = System.Web.Mail.MailFormat.Html;
string[] FormFields = new string[2];
StringBuilder tableBody = new StringBuilder("<table>");
string mailBody;

FormFields[0] ="<strong>" "</strong>";
FormFields[1] ="<strong>" "</strong>";


for(int i = 0; i < 2; i++)
{
tableBody.Append("<tr><td class='title'>" + FormFields[i] + "</td><td class='response'>");
switch(i)
{

case 0:
tableBody.Append("<h2>Details here</h2>");
break;
case 1:
foreach (Control ctrl in PlaceHolder1.Controls)
{

}
break;

}
}
Mar 16 '07 #1
0 977

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Bas Groeneveld | last post: by
4 posts views Thread by Harry | last post: by
1 post views Thread by jelle.huygen | last post: by
5 posts views Thread by Nathan Sokalski | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.