P
Phuff
I need to add controls on a button click. I would prefer to do this in
the page load or init functions, however due to the nature of the page
I have to add them later on. When I try to enumerate through the place
holder's control collection is always at 0. How can I get to the text
of these texbox controls that I added?
Here's the coded with email information @@@@@'d out.
ADDING THE CONTROLS:
for (int i = 0; i < lister.Length; i++)
{
Label tmpLabel = new Label();
TextBox tmpTxt = new TextBox();
tmpLabel.Attributes.Add("runat", "server");
tmpLabel.ID = "lblSub" + i.ToString();
tmpLabel.Text = "Subject for " + lister;
tmpTxt.Attributes.Add("runat", "server");
tmpTxt.ID = lister;
tmpTxt.Width = Unit.Pixel(275);
tmpTxt.Text = lister + " - " + bldSite.Value;
subjPlace.Controls.Add(tmpLabel);
subjPlace.Controls.Add(tmpTxt);
subjPlace.Controls.Add(new LiteralControl("<br />"));
}
ENUMERATING THROUGH:
foreach (Control c in form1.Controls)
{
if (c.GetType().ToString() ==
"System.Web.UI.WebControls.PlaceHolder")
{
foreach (Control ctr in c.Controls)
{
if (ctr.GetType().ToString() ==
"System.Web.UI.WebControls.TextBox")
{
string jobStr = ((TextBox)ctr).ID;
//string subject = subjPlace.;
string userEmail =
Request.LogonUserIdentity.Name.Replace("@@@\\", "") + "@@@@@@";
string[] parameters = new string[5];
//TODO: Fill parameters with data
parameters[0] =
Request.QueryString["quote"];
parameters[1] =
Request.QueryString["order"];
parameters[2] =
ds.Tables[0].Rows[0]["CustNam"].ToString();
parameters[3] =
ds.Tables[0].Rows[0]["QuotedBy"].ToString();
parameters[4] =
ds.Tables[0].Rows[0]["BldSite"].ToString();
string strEmailText = string.Format("------
Release to Shop Information ------\n\n"
+
"Customer Name : {2}\n"
+
"Quote # : {0}\n"
+
"Order # : {1}\n"
+
"Quoted By : {3}\n"
+
"Build Site : {4}\n\n", parameters);
strEmailText += "--------------- Job Files
---------------\n\n";
for (int i = 0; i < files.Length; i++)
{
if (files.Contains(jobStr))
{
strEmailText += files + "\n";
}
}
System.Net.Mail.MailMessage Mail = new
System.Net.Mail.MailMessage();
System.Net.Mail.MailAddress add = new
System.Net.Mail.MailAddress(userEmail);
Mail.From = add;
Mail.To.Add("@@@@@@@@");
System.Net.Mail.SmtpClient mailer = new
System.Net.Mail.SmtpClient("email");
try
{
Mail.Subject = ((TextBox)ctr).Text;
Mail.Body = strEmailText;
mailer.Send(Mail);
}
catch (Exception ex)
{
writeTrace(ex.Message + "[METHOD:
emailSTS] (" + DateTime.Now + ")", "ERROR");
}
}
}
}
}
}
catch (Exception ex)
{
writeTrace(ex.Message + "[METHOD: emailSTS] (" +
DateTime.Now + ")", "ERROR");
}
the page load or init functions, however due to the nature of the page
I have to add them later on. When I try to enumerate through the place
holder's control collection is always at 0. How can I get to the text
of these texbox controls that I added?
Here's the coded with email information @@@@@'d out.
ADDING THE CONTROLS:
for (int i = 0; i < lister.Length; i++)
{
Label tmpLabel = new Label();
TextBox tmpTxt = new TextBox();
tmpLabel.Attributes.Add("runat", "server");
tmpLabel.ID = "lblSub" + i.ToString();
tmpLabel.Text = "Subject for " + lister;
tmpTxt.Attributes.Add("runat", "server");
tmpTxt.ID = lister;
tmpTxt.Width = Unit.Pixel(275);
tmpTxt.Text = lister + " - " + bldSite.Value;
subjPlace.Controls.Add(tmpLabel);
subjPlace.Controls.Add(tmpTxt);
subjPlace.Controls.Add(new LiteralControl("<br />"));
}
ENUMERATING THROUGH:
foreach (Control c in form1.Controls)
{
if (c.GetType().ToString() ==
"System.Web.UI.WebControls.PlaceHolder")
{
foreach (Control ctr in c.Controls)
{
if (ctr.GetType().ToString() ==
"System.Web.UI.WebControls.TextBox")
{
string jobStr = ((TextBox)ctr).ID;
//string subject = subjPlace.;
string userEmail =
Request.LogonUserIdentity.Name.Replace("@@@\\", "") + "@@@@@@";
string[] parameters = new string[5];
//TODO: Fill parameters with data
parameters[0] =
Request.QueryString["quote"];
parameters[1] =
Request.QueryString["order"];
parameters[2] =
ds.Tables[0].Rows[0]["CustNam"].ToString();
parameters[3] =
ds.Tables[0].Rows[0]["QuotedBy"].ToString();
parameters[4] =
ds.Tables[0].Rows[0]["BldSite"].ToString();
string strEmailText = string.Format("------
Release to Shop Information ------\n\n"
+
"Customer Name : {2}\n"
+
"Quote # : {0}\n"
+
"Order # : {1}\n"
+
"Quoted By : {3}\n"
+
"Build Site : {4}\n\n", parameters);
strEmailText += "--------------- Job Files
---------------\n\n";
for (int i = 0; i < files.Length; i++)
{
if (files.Contains(jobStr))
{
strEmailText += files + "\n";
}
}
System.Net.Mail.MailMessage Mail = new
System.Net.Mail.MailMessage();
System.Net.Mail.MailAddress add = new
System.Net.Mail.MailAddress(userEmail);
Mail.From = add;
Mail.To.Add("@@@@@@@@");
System.Net.Mail.SmtpClient mailer = new
System.Net.Mail.SmtpClient("email");
try
{
Mail.Subject = ((TextBox)ctr).Text;
Mail.Body = strEmailText;
mailer.Send(Mail);
}
catch (Exception ex)
{
writeTrace(ex.Message + "[METHOD:
emailSTS] (" + DateTime.Now + ")", "ERROR");
}
}
}
}
}
}
catch (Exception ex)
{
writeTrace(ex.Message + "[METHOD: emailSTS] (" +
DateTime.Now + ")", "ERROR");
}