Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 12th, 2008, 01:00 PM
Authorized User
 
Join Date: Jul 2007
Location: Cumming, Ga, USA.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to u2clone
Default How do I clear a form after it has been submitted?

Howdy, here is my problem. I have a form on my site that when filled out, emails the response to me. I configured it so that the Label underneath confirms to the user the request was submitted. WHat is missing is the form wiping itself clean. Below is the code behind (I am using c# by the way). What do I need to do for the form to reset?

        try
        {

            MailMessage message = new MailMessage();
            message.To.Add("emal addy here");
            message.From = new MailAddress("britt@ecommerceenginuity.com");
            message.Subject = "Test Email";
            message.Body = "Name: " + FirstName.Text + " " + LastName.Text + "\r\n" + "Email: " + EmailAddress.Text + "\r\n" + "Phone: " + Phone.Text + "\r\n" + "Zip Code: " + ZipCode.Text + "\r\n" + "Plumbing Need: " + PlumbingNeed.Text;
            System.Net.Mail.SmtpClient oClient = new System.Net.Mail.SmtpClient();
            oClient.Send(message);


        }
        catch (Exception ex)
        {
            Response.Write("Send failure: " + ex.ToString());
        }

Any help would be appreciated.

"Freedom is the right of all sentient beings" - Optimus Prime
__________________
\"Freedom is the right of all sentient beings\" - Optimus Prime
 
Old February 12th, 2008, 01:39 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Explicitly clear your controls:

e.g.
FirstName.Text = "";
LastName.Text = "";

Thumbs up for the Transformer reference. =]


================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old February 12th, 2008, 01:44 PM
Authorized User
 
Join Date: Jul 2007
Location: Cumming, Ga, USA.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to u2clone
Default

Where do I drop that in the code? I assume after the 'catch'... Do I need to add a command before the FirstName, etc?

I have a better transformer ref on my IM - Optimus standing at a podium winning the presidential election. Heehee

"Freedom is the right of all sentient beings" - Optimus Prime
 
Old February 12th, 2008, 01:53 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You can place it anywhere after the construction of the Body for the email message just not in the catch{}, obvioulsy.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old February 12th, 2008, 02:09 PM
Authorized User
 
Join Date: Jul 2007
Location: Cumming, Ga, USA.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to u2clone
Default

Great! That is working...thanks so much!

What about it resetting my DropDown and List Box (just added) to unselcted Items?

"Freedom is the right of all sentient beings" - Optimus Prime
 
Old February 12th, 2008, 02:39 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Do you really want to reset your controls? Or do you just want them to get out of the way with their current values?

You could also wrap them all in an asp:PlaceHolder control and then set that control's Visible property to False after you have sent the message. That way, you can hide them in one fell swoop.

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old February 12th, 2008, 02:43 PM
Authorized User
 
Join Date: Jul 2007
Location: Cumming, Ga, USA.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to u2clone
Default

I want to reset the controls. If I wanted to hide the form I'd shoot off to a thank you page or something. I want the reset controls with the Label underneath letting the user know their request was sent (I have that working just need the reset).

Same form, different question as I am working on it...do you know how to send all selected values from a listbox in the email that the form fires? It will send the first, but not the rest...Hmmmmmm

"Freedom is the right of all sentient beings" - Optimus Prime
 
Old February 12th, 2008, 04:00 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You can use the ListBox ClearSelection method to unselect all of the items in the list so:

listBox1.ClearSelection();

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========




Similar Threads
Thread Thread Starter Forum Replies Last Post
how to avoid a frame from getting submitted premnaath ASP.NET 2.0 Professional 1 November 5th, 2007 08:24 AM
The request could not be submitted for background mvilas Crystal Reports 2 November 1st, 2006 08:20 PM
the correct way to clear a form field in js crmpicco Javascript How-To 3 March 21st, 2006 08:44 AM
How to clear all text box in a form at once time richie86 ASP.NET 1.0 and 1.1 Basics 1 October 31st, 2005 04:57 AM
Getting the submitted fields in a form siraj_java Javascript How-To 0 August 26th, 2003 12:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.