Variable Scope in asp.Net

Discussion in 'Software' started by jansi_rk, Sep 6, 2006.

  1. jansi_rk

    jansi_rk

    Joined:
    Sep 6, 2006
    Messages:
    1
    Hi
    I have one problem with using variables in asp.net with C# application. I declared one variable as public and initialized the value for the variable in one event and when calling the value in another event it returns zero in that event. So plz help me hw to call the value in that event.

    EXample Code
    public int MyRowcount; // Variable Initialization

    public void Button1_Click(object sender, System.EventArgs e)
    {
    MyRowcount=5; //assigning Value to the variable
    }
    public void Button2_Click(object sender, System.EventArgs e)
    {

    Response.Write(MyRowcount); //It returns zero value(I want it should return 5)
    }

    advance in thanks
    Jansi Rajkumar. T
    }
    jansi_rk, Sep 6, 2006
    #1
    1. Advertising

  2. jansi_rk

    BabuA

    Joined:
    Sep 12, 2006
    Messages:
    6
    Location:
    BANGALORE,INDIA
    Hi Jansi_rk,

    if you delclare your variable with static modifier, then it will be available to all the events with in the scope availabe, as follows

    public static int MyRowcount;

    Babu
    BabuA, Sep 18, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?c2FuanU=?=

    information about asp ,oracle,asp.net certification?

    =?Utf-8?B?c2FuanU=?=, May 18, 2005, in forum: Microsoft Certification
    Replies:
    1
    Views:
    503
    Bob Christian
    May 18, 2005
  2. Zabron Muyambo

    Easy Moving from ASP to ASP.NET???

    Zabron Muyambo, Oct 26, 2004, in forum: MCSD
    Replies:
    7
    Views:
    490
    Zabron Muyambo
    Oct 27, 2004
  3. thehobbit
    Replies:
    0
    Views:
    3,698
    thehobbit
    Nov 22, 2006
  4. toller

    Variable scope

    toller, Apr 21, 2008, in forum: Hardware
    Replies:
    1
    Views:
    874
    toller
    Apr 21, 2008
  5. london1919
    Replies:
    1
    Views:
    2,881
    Lawrence Garvin \(MVP\)
    Dec 8, 2008
Loading...

Share This Page