1 Replies - 2581 Views - Last Post: 14 June 2010 - 06:49 AM Rate Topic: -----

#1 Guest_abid wali khan*


page wise global variables

Posted 12 June 2010 - 12:58 AM

hello , i need to declare a global variable string "strpolladdress" in my aspx.cs page and instantiate the variable's value from backend database and then use this value in 3 or 4 different methods in same aspx.cs code behind page.
The value of variable can be read and is okay as long as I remain in the same method in which its value is
instantiated but I get null values in rest of the methods on same aspx.cs page :( , someone help me out

thanks :)

Is This A Good Question/Topic? 0

Replies To: page wise global variables

#2 Frinavale   User is offline

  • D.I.C Addict
  • member icon

Reputation: 205
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: page wise global variables

Posted 14 June 2010 - 06:49 AM

It sounds like you're declaring this variable within a method but you should be declaring this variable at page level.

You should have something like:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;

namespace WebApplication2
  public partial class _Default : System.Web.UI.Page
    private string _strpolladdress; //will contain the string
    protected void Page_Load(object sender, EventArgs e)
      //initialize _strpolladdress with data from the database...
    private void methodA(){
      //do stuff with _strpolladdress
    private void methodB(){
      //do stuff with _strpolladdress

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1