C# variables question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cathy25
    New Member
    • Oct 2007
    • 21

    C# variables question

    Hi,

    Is it possible to declare a variable in On_load event of a page and use the same variable in On_click event (button) of the same page?
    If yes, How do we need to declare the variable?

    Can any body reply me.

    Thanks
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by cathy25
    Hi,

    Is it possible to declare a variable in On_load event of a page and use the same variable in On_click event (button) of the same page?
    If yes, How do we need to declare the variable?

    Can any body reply me.

    Thanks
    Yes this is possible.
    You have to declare the variable as such:

    [code=vbnet]
    Private myVariable As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load
    ' .....
    myVariable="hel lo world"
    End Sub

    Protected Sub BTN_MyButton_Cl ick(ByVal sender As Object, ByVal e As System.EventArg s) Handles BTN_MyButton.Cl ick
    LBL_myLabel.Tex t=myVariable
    End Sub
    [/code]

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Originally posted by Frinavale
      Yes this is possible.
      You have to declare the variable as such:

      [code=vbnet]
      Private myVariable As String

      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load
      ' .....
      myVariable="hel lo world"
      End Sub

      Protected Sub BTN_MyButton_Cl ick(ByVal sender As Object, ByVal e As System.EventArg s) Handles BTN_MyButton.Cl ick
      LBL_myLabel.Tex t=myVariable
      End Sub
      [/code]
      OH whoops didn't realize you were asking about C#....anyways I'm sure you get the idea from the VB.NET code :)

      -Frinny

      Comment

      Working...