473,387 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Placeholder and Dynamic controls - help!

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[i];

tmpTxt.Attributes.Add("runat", "server");
tmpTxt.ID = lister[i];
tmpTxt.Width = Unit.Pixel(275);
tmpTxt.Text = lister[i] + " - " + 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[i].Contains(jobStr))
{
strEmailText += files[i] + "\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");
}

Nov 2 '06 #1
2 7343
What you can do is declare an instance of each type of object. Then
using the FindControl function you can bind each instance to the
control itself and then retrieve the data within it. So, for example:

'Create an instance of the object
Dim i as TextBox()

'Bind the control the your instance in memory
'(placeHolder would be the name of your Place Holder object)
i = placeHolder.FindControl("txtMyTextBox")

'Output the TextBoxes contents
Response.Write(i.Text)

I'm not sure I got the syntax entirely correct, but something along
those lines using the FindControl function should do what your looking
for.

Nick

Nov 2 '06 #2
Nick,

Thanks for your response. I gave that a try but no go. For some
reason the place holder's control collection is empty. It's like the
controls are not being added to the view state. This is some what
frustrating. I'm sure I could have used some other approaches, but
isn't quick and simple supposed to be the credo of .Net? What's going
on here? Anyway, I'll keep digging.

I guess I'll create a hidden field, those are working correctly, and
use javascript to fill the hidden field value for the client onchange
event of the textbox. Then I'll just parse the hidden field's value.
Quite the annoying workaround, but what are you going to do, right?

Thanks,

Paul
ns***********@gmail.com wrote:
What you can do is declare an instance of each type of object. Then
using the FindControl function you can bind each instance to the
control itself and then retrieve the data within it. So, for example:

'Create an instance of the object
Dim i as TextBox()

'Bind the control the your instance in memory
'(placeHolder would be the name of your Place Holder object)
i = placeHolder.FindControl("txtMyTextBox")

'Output the TextBoxes contents
Response.Write(i.Text)

I'm not sure I got the syntax entirely correct, but something along
those lines using the FindControl function should do what your looking
for.

Nick
Nov 3 '06 #3

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

Similar topics

2
by: theo | last post by:
Hi... I wish to extract the text content of an Xml file and assign it to DropDownList controls at runtime.I can get the Xml file text content into the DropDownList controls (Ex...if 5 Xml text...
4
by: blue | last post by:
I have a drop-down list, a radio button list and a submit button. I'm adding these controls to a table and I'm adding the table to a Placeholder. I'm adding it to the Placeholder because I don't...
2
by: Mike Speak | last post by:
I have a user control that I want to use to render 4 menu items (retrieved from db) on the top of each of my asp.net pages. The user control defines a table, with one TR and one TD. Within the...
0
by: shark | last post by:
I have a placeholder in a control that is in turn, used as a control in a placeholder in a form. I am getting a viewstate error so I believe I have to clear my placeholder before I load the...
1
by: Amir Ghezelbash | last post by:
Hey every body; first off let me say thanks every body..this place is great i have never came here with a problem and left without an answer..you guys are awsome any way i had a question...
3
by: PKin via DotNetMonster.com | last post by:
Hi, I have a web page with a radioButtonList with 3 buttons (B1,B2 and B3) and a placeholder. B1 will put an .ascx file (Pl1.ascx) in the placeHolder, B2 will do the same with Pl2.ascx and B3...
1
by: Joe | last post by:
Hello All, I have a user control which is composed of a label and a dropdownlist. In my code I add the user control to a placeholder on the webform. Now I want to be able to retrieve the...
6
by: David Colliver | last post by:
Hi, using vb.net 1.1 I am trying to add a control to a placeholder but am having problems with it. I do it practically the same way as i do in C# (I have more C# skill than VB.NET)and I...
7
by: Brad Baker | last post by:
I am trying to programmatically set a placeholder control in csharp which is nested inside a repeater control between <ItemTemplateand </ItemTemplate> tags, however I am running into problems. I've...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...

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.