How to clear form after postback

D

Dave

Hi,

I have an asp.net page with a form. When the submit button is clicked it
sends an email.

When the page reloads the form fields are still filled with the info that
just got submitted.

I tried
<%@ Page EnableViewState="false" %>
but it doesn't clear the form.

I also tried EnableViewState="false" in each form element and that doesn't
work either.

How can I disable the postback information?

Thanks!!!
 
H

Hans Kesting

Dave said:
Hi,

I have an asp.net page with a form. When the submit button is clicked it
sends an email.

When the page reloads the form fields are still filled with the info that
just got submitted.

I tried
<%@ Page EnableViewState="false" %>
but it doesn't clear the form.

I also tried EnableViewState="false" in each form element and that doesn't
work either.

How can I disable the postback information?

Thanks!!!

This is standard Postback behavior that is very useful when you have server-side validators.

You have two options:
1) when the email is successfully sent, clear all fields
2) do a redirect (to the same url), after sending.

The disadvantage of 1 is that when the user refreshes the page,
the email might get sent again (this empty page was the result of a
form submission, refresh submits the original form again ...).
You don't have that problem with 2.

Hans Kesting
 
O

One Handed Man \( OHM - Terry Burns \)

One question. If you use method 2, will this not start a new session each
time. ?, if so this could eat up a lot of memory if someone is sitting there
sending loads of emails

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
H

Hans Kesting

One Handed Man ( OHM - Terry Burns ) said:
One question. If you use method 2, will this not start a new session each
time. ?, if so this could eat up a lot of memory if someone is sitting there
sending loads of emails

No, a redirect leaves you in the same session.

Some reasons to get a new session:
*) When you first close all browser windows (so that the session-cookie
gets destroyed) and then open a new one.
*) When you use a browser of a different brand (or maybe a new instance
of your current browser, "new window" usually is NOT enough)
*) When you don't access the site for (default) 20 minutes.
*) When the server code specifies that the session should be destroyed
(maybe after a "logout")

Hans Kesting
 
O

One Handed Man \( OHM - Terry Burns \)

Thanks

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

Hans Kesting said:
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
message news:[email protected]...
 
D

Dave

Thanks Hans,

That seems to work.

I put redirect after the email send line.

The first time I submitted the page it didn't load the page though. The
page came up with a link. Click the link and it loads the page.

Subsequent submits came up correctly.

Is that right?

BTW, this is off topic, but how can I submit a page using an image and not a
button in asp.net?

Thanks!!!
Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top