can I force Page.IsPostBack=false ?

G

Guy Noir

Hello again. I have a form that has 2 buttons. When button 1 is
pressed, I want the form to execute a few tasks and give the user
feedback. When button 2 is pressed, I want the form to reload as if it
is being called for the first time. That is, I want the code in
Page_Load if (!Page.IsPostBack) to execute as if we are calling the
page for the first time.

I guess I could do a server redirect or whatever, but is there a more
elegant solution?

TIA.
-Guy
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Guy said:
Hello again. I have a form that has 2 buttons. When button 1 is
pressed, I want the form to execute a few tasks and give the user
feedback. When button 2 is pressed, I want the form to reload as if it
is being called for the first time. That is, I want the code in
Page_Load if (!Page.IsPostBack) to execute as if we are calling the
page for the first time.

I guess I could do a server redirect or whatever, but is there a more
elegant solution?

TIA.
-Guy

Use a link to the page, or the Javascript equivalent:

<input type="button" value="Restart"
onclick="window.location='ThePage.aspx';" />
 
M

Mark Fitzpatrick

You could put the code that is called in the Page_Load into a function so
you could code like so:

if(!Page.IsPostBack)
{
MyFunction();
}

Then in the button's click handler you can just call the function directly.
You don't have to bother with checking for a postback.
 
G

Guy Noir

Mark said:
You could put the code that is called in the Page_Load into a function so
you could code like so:

if(!Page.IsPostBack)
{
MyFunction();
}

Then in the button's click handler you can just call the function directly.
You don't have to bother with checking for a postback.
Ahh excellent. Thanks much for the tip.
 

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

Similar Threads

page.ispostback question 14
Page.IsPostBack Property 5
event not FIRE 1
If Not Page.IsPostBack Then <-- HELP!!! 4
Page Reload 2
Page.IsPostBack 3
!Page.IsPostBack 1
Disabling buttons in ASP.net 1.1 3

Top