I have come to realize that these values will pass the initial/first value of the first ListItem if there are duplicates or I can put a single space after the second duplicate, double space after the 3rd duplicate etc. and it will work (although not a proper coding technique).
My problem is if I select something like Product.
I will get Email1 but I get the text Problem instead of Product.
I have zero coding experience so if this is a pain, feel free to forward me to ASP.NET to get an education. I might just pawn it off to a prpgramming group nearby.
You can tell how new I am to programming by my thoughts on your reply. I read your reply and got down to “You could also just parse the text through” and I said, uhm, der, what do you mean.
First off, I thought I’ld give a piece of advice. If you were working for me, and wrote an asp.net program which had business logic built into the presentation layer, I would take you out and shoot you (Harsh but I feel fair). To make it clearer, values like Problem, Product or Complaint would be stored in a database, config file or resource file combined with a field/value that states which email they fire. Hence the logic would be nowhere near the asp page. This allows the business logic of the website to be configurable, easy to update and easy to document.
BUT, BUT, BUT,
Sometimes you don’t care. You get paid whether you do this job, well or badly. Sometimes the less programming you do, the more time you have for the pub. So why not just put a switch in the code behind, or clientside javascript if thats where it is needed. I would have thought a switch case block would make more sense to you and subsequent programmers, than something obtuse hidden within the <asp : DropDownList>
"When the solution is simple, God is answering. " - Albert Einstein
I am NOT a programmer, just a pee-on coordinator that’s left holding the bag.
I’ve done my share of HTML, Coldfusion etc. but nothing I would consider ‘programming’. THat’s for smart people like you two.
I agree, I would shoot me too, having the email in the value field is horrible and I’m looking for direction. I would possibly be able to look up info on how to add to the code behind, it’s in C#.
The current configuration is a mess and I’m trying to straighten out as much as I can on a limited budget (ie; no programming staff or web admin).
Where can I learn more about switches and see examples in action. I’m a “Jack of all Trades” so I’m confident I can learn the right way given time.
Thanks for the comments, I don’t think anything thus far was harsh and I consider the current layout ‘Balogne’ (sp?)
strForwardMail should contain the correct value your looking for. I would not hit the db just for a simple contact us form unless it could expand in the future, but i would rather have if/switch statments set the email address:
if (strQuestion=="Product" || strQuestion=="Problem")
{
strForwardMail="support@domain.com";
}
else if (strQuestion=="Complaint" || strQuestion=="Question")
{
strForwardMail="sales@domain.com";
}
else
{
strForwardMail="default@domain.com";
}
Fourth, in the method handling the submit, lookup the address in your dictionary:
EmailTarget et = null;
Targets.TryGetValue(EmailTarget.SelectedValue, out et);
if (et == null)
{
throw new ArgumentOutOfRangeException("EmailTarget", "Selected email target does not exist. This is probably a spambot.");
}
//use the et.EmailAddress field as appropriate.
I placed your code after I declare the question and forward mail variables.
Then, I took the Value and Text from ListItem in the form and moved text between:
<asp:ListItem>Choose One</asp:ListItem>
Thanks for the assistance, you saved me another 4 hours of frantic searching.
Nothing, it is just a better way of doing it. With proper OO principals. And its abstracting the code if you need to use it elsewhere. I would have done something similar, but thought it might be a bit over your head if your not a programmer. But if you understand it I would also suggest that method.
oh, and also then the values will not be email addresses in the drop down list