Home » ASP.NET

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

5 October 2007 292 views No Comment Popularity: 3% 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. Cascading StyleSheet (CSS) :: Property Value Pairs
  3. Wordpress: Optimizing 404 Page Not Found page
  4. How to show child page (sub page) list in parent page in wordpress?
  5. Simple and easy jQuery tabs with AJAX and PHP

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.