4 Replies - 599 Views - Last Post: 22 April 2010 - 11:53 PM Rate Topic: -----

#1 ans2007kumar   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 25-September 09

ASP.net Question

Posted 22 April 2010 - 08:37 AM

I want to know in this code where i should declare a global integer variable so that its value not initialized to '0' on page post-back
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Error : System.Web.UI.Page
{
//here??
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}


or there is no possible at all

Is This A Good Question/Topic? 0
  • +

Replies To: ASP.net Question

#2 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: ASP.net Question

Posted 22 April 2010 - 09:47 AM

you could declare it there as long as you don't set it to a value there, but you might look at storing it in a session variable
Was This Post Helpful? 0
  • +
  • -

#3 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1533
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: ASP.net Question

Posted 22 April 2010 - 07:07 PM

It doesn't matter where you put it. It will always be set to 0 on a post-back. If you want to store values across post-backs, you should look into storing them in the Session.
Was This Post Helpful? 0
  • +
  • -

#4 cpuguru07   User is offline

  • New D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 21-February 09

Re: ASP.net Question

Posted 22 April 2010 - 11:04 PM

View Postans2007kumar, on 22 April 2010 - 09:37 AM, said:

I want to know in this code where i should declare a global integer variable so that its value not initialized to '0' on page post-back


You could declare it there first, then initialize it inside an if statement that will only initialize it if the page was not posted back:

public partial class Error : System.Web.UI.Page
{
    public int sample;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            sample = 0;
        }
    }
}


This post has been edited by cpuguru07: 22 April 2010 - 11:04 PM

Was This Post Helpful? 0
  • +
  • -

#5 ans2007kumar   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 25-September 09

Re: ASP.net Question

Posted 22 April 2010 - 11:53 PM

thankx for the help
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1