473,395 Members | 1,745 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,395 software developers and data experts.

Accessing DropDownList info and values that aren't known until runtime?

This is a crosspost from a less-frequented (but more focused) asp.net group;
I didn't receive an answer that worked. I'd like to get this form
functional. Could someone help on what's probably a simple syntax issue?
I've attempted my due diligence with the usual books and references...but
I'm new to ASP.NET. Question follows:

The Code Project has a nice article on making a "self configuring form
mailer web control." Basically, you apply this control to any form with
ASP.NET textbox server controls on it and it turns the form into something
that's automatically mailed out to an e-mail you specify. Read all about it
here:
http://www.codeproject.com/aspnet/Se...FormMailer.asp

The code works great for textboxes. The author of the article leaves it as
"an exercise for the reader" to configure the program for other types of
controls. The relevant section of code reads as follows:

{
if (control is TextBox)
{
TextBox textBox = (TextBox)control;
if (textBox.Text.Length > 0)
{
if (textBox.ID.ToLower().EndsWith("subject"))
{
subject = textBox.Text; // subject is added as a mail header later
in the code
}
else if (textBox.ID.ToLower().EndsWith("emailaddress"))
{
replyTo = textBox.Text; // add a reply-to header, and
// append the to the text of the message
messageText.Append(mailTemplate.getTemplateText(te xtBox.ID,
textBox.Text));
}
else
{ // general case, just append to the email body
messageText.Append(mailTemplate.getTemplateText(te xtBox.ID,
textBox.Text));
}
}
}
// >>> add more types of controls within else if clauses here <<<
}

So what you have going on is the script generates an e-mail string at
runtime using the IDs and Text that are specified by the form developer.

I want the script to work with DropDownLists. I can't figure out how to make
it access the values of the selected listitems. Most of the dropdown scripts
I've seen around the net presume that the name of the parent control
(DropDownList) is specified prior to runtime, but wiring this information in
defeats the point of this generic script.

I've tried a +lot+ of variations, e.g.:
messageText.Append(mailTemplate.getTemplateText(Dr opDownList.ID.Selecteditem
..Value, DropDownList.ID.Selecteditem.Text))

No joy so far. Can someone help out with what's probably an easy question?

Thanks,

Ken Fine
Nov 19 '05 #1
1 1299
> if (control is TextBox)
{
TextBox textBox = (TextBox)control;
if (textBox.Text.Length > 0)
I imagine you would do something like this:

if (control is DropDownList)
{
DropDownList dList = (DropDownList)control;
if(dList.Selectedindex > 0)
etc etc etc

Lowell


ke*****@u.washington.edu wrote: This is a crosspost from a less-frequented (but more focused) asp.net group;
I didn't receive an answer that worked. I'd like to get this form
functional. Could someone help on what's probably a simple syntax issue?
I've attempted my due diligence with the usual books and references...but
I'm new to ASP.NET. Question follows:

The Code Project has a nice article on making a "self configuring form
mailer web control." Basically, you apply this control to any form with
ASP.NET textbox server controls on it and it turns the form into something
that's automatically mailed out to an e-mail you specify. Read all about it
here:
http://www.codeproject.com/aspnet/Se...FormMailer.asp

The code works great for textboxes. The author of the article leaves it as
"an exercise for the reader" to configure the program for other types of
controls. The relevant section of code reads as follows:

{
if (control is TextBox)
{
TextBox textBox = (TextBox)control;
if (textBox.Text.Length > 0)
{
if (textBox.ID.ToLower().EndsWith("subject"))
{
subject = textBox.Text; // subject is added as a mail header later
in the code
}
else if (textBox.ID.ToLower().EndsWith("emailaddress"))
{
replyTo = textBox.Text; // add a reply-to header, and
// append the to the text of the message
messageText.Append(mailTemplate.getTemplateText(te xtBox.ID,
textBox.Text));
}
else
{ // general case, just append to the email body
messageText.Append(mailTemplate.getTemplateText(te xtBox.ID,
textBox.Text));
}
}
}
// >>> add more types of controls within else if clauses here <<<
}

So what you have going on is the script generates an e-mail string at
runtime using the IDs and Text that are specified by the form developer.

I want the script to work with DropDownLists. I can't figure out how to make
it access the values of the selected listitems. Most of the dropdown scripts
I've seen around the net presume that the name of the parent control
(DropDownList) is specified prior to runtime, but wiring this information in
defeats the point of this generic script.

I've tried a +lot+ of variations, e.g.:
messageText.Append(mailTemplate.getTemplateText(Dr opDownList.ID.Selecteditem
.Value, DropDownList.ID.Selecteditem.Text))

No joy so far. Can someone help out with what's probably an easy question?

Thanks,

Ken Fine

Nov 19 '05 #2

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

Similar topics

0
by: Jeff | last post by:
After I bind the repeater control in the form_load event, it builds multiple lines based on the number of rows in the dataset. In the repeater control, I have a textbox and a dropdown list box. ...
2
by: Shiju Poyilil | last post by:
Hi ! I have a requirement wherein i am binding a datalist which contains a label (Caption for the field) and some literal hidden fields and a dropdown list. When I am binding to the datalist.....
1
by: Jeff Smith | last post by:
Can I load custom web user controls dynamically and access the properties and methods without having to explicitly define custom control types (example 2 below). I have custom web control named...
10
by: Sacha Korell | last post by:
I'm trying to load a drop-down list with all DropDownList control names from another page. How would I be able to find those DropDownList controls? The FindControl method will only find a...
13
by: Joseph Garvin | last post by:
When I first came to Python I did a lot of C style loops like this: for i in range(len(myarray)): print myarray Obviously the more pythonic way is: for i in my array: print i
2
by: Brenden Bixler | last post by:
I have a user control, dropdown.ascx Inside dropdown.ascx, I have a dropdownlist control. From my page.aspx, I need to be able to access the dropdown's value. By setting it to auto-post...
9
by: J055 | last post by:
Hi I have a standard asp page which uses a MasterPage. The MasterPage contains a User control. How can I access a public method in the User control from my WebForm page? I can't move the method...
4
by: =?Utf-8?B?R3JlZyBTdGV2ZW5z?= | last post by:
I have an ASP.NET page with a form that contains two user controls: <%@ Register TagPrefix="x" TagName="c1" Src="ctl1.ascx" %> <%@ Register TagPrefix="x" TagName="c2" Src="ctl2.ascx" %> <body>...
2
by: sree reddy | last post by:
..cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls;
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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...
0
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...

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.