Boardy
Boardy

Reputation: 36237

Check if form has submitted in aspx

all I have an ASP form. When the page loads it runs a method using the Page_Load event handler. When the user submits the form if it didn't correctly revalidate it returns to the page but I do not want the method for the Page_Load to run.

Is there a way I can check if the form has been submitted previously without needing to check a specific field within the form.

Thanks for any help you can provide.

Upvotes: 2

Views: 7606

Answers (2)

Jeremy
Jeremy

Reputation: 46420

In your Page_Load method, only do your processing if IsPostBack is false)

//Page_Load method
If (!IsPostBack)
{
  // Code in here should only run when the page first loads.  
  // It will not run if a user clicks a button on the page.
}

Upvotes: 6

Tom Gullen
Tom Gullen

Reputation: 61775

Try this:

if(IsPostBack){

    Response.Write("Form posted!");

}

http://msdn.microsoft.com/en-us/library/system.web.ui.page.ispostback.aspx

Upvotes: 2

Related Questions