Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

In my website, I have a button which when clicked builds a query string based on data input by the user into several checked list views and redirects to the same page with the new query string. On button click, the page load is executed first and then the button click event where redirection occurs and again a page load is executed. I want to avoid 2 postbacks from occuring. Checking Page.IsPostBack happens inside Page Load, so it cannot avoid a postback. Kindly help.

Thanks & regards.
Posted
Updated 7-Mar-10 23:55pm
v3

Use !Page.IsPostback in Page_Load event.
The code is like that given below:

private void Page_Load()
{
    if (!Page.IsPostBack)
    {
        Validate();
    }
}
 
Share this answer
 
v2
You cannot avoid two postbacks because one postback is pushed from the button click event and another from the Page redirection. What can you do here? You can check the Page.IsPostBack property,and can avoid calling all the functions on Page load.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900