Home » ASP.NET

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

5 October 2007 49 views No Comment

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

Popularity: 2%

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. ASP.NET Error : An HtmlSelect cannot have multiple items selected when Multiple is false.
  4. Solution: Google Adsense not showing on my website blog
  5. How to show child page (sub page) list in parent page in wordpress?
Share/Bookmark
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

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.