Home » ASP.NET

Page.IsPostBack property: A solution to the client postback problem

5 October 2007 1,067 views Popularity: 2% Share/Bookmark

Problem

There is a .aspx page with some textbox and a submit button.

User enters text in the textbox and clicks the submit button.

Then the system shows that the data has been successfully posted or updated.

But, when we view the database, the data just posted is not entered/updated there.

Solution

Use Page.IsPostBack property.

This property returns only a Boolean value: true if the page is being loaded in response to a client postback; otherwise, false. Default value is false.

More clearly:

1) IsPostBack returns false if the page is being loaded and accessed for the first time

2) IsPostBack returns true if the page is being loaded in response to a client postback.


Sample C# code:

private void Page_Load(object sender, System.EventArgs e)
{

if(!Page.IsPostBack)

{

// your code to update/insert into database

}

}

I had this problem when I was doing my semester project on ASP.NET and C#, one year back (well, at that time I had just started learning ASP.NET and C#). Then I googled the internet and found out about panel system (asp:Panel) in ASP.NET, i.e. using different panels to display and edit record/data. This took a lot of time to code and even manage the code and design as well. I had to write the same code twice. I found it very ineffective and again searched for a proper solution. Then I got to learn about IsPostBack property and all my hurdles were gone.

Cheers,

Mukesh

From Mukesh Chapagain's Blog, post Page.IsPostBack property: A solution to the client postback problem

Related posts:

  1. ASP.NET Error: A potentially dangerous Request.Form value was detected from the client
  2. Magento: Solution to “Error: 404 Not Found” in Admin Login Page
  3. Cascading StyleSheet (CSS) :: Property Value Pairs
  4. How to show child page (sub page) list in parent page in wordpress?
  5. MySQL Installation Problem
  6. Magento Admin login problem
  7. Magento: Enable Cookies Problem
  8. ASP.NET Error : An HtmlSelect cannot have multiple items selected when Multiple is false.
  9. WordPress: Optimizing 404 Page Not Found page
  10. Dynamically change page title and meta tags in C#