Losing Global Variables

Results 1 to 2 of 2

Thread: Losing Global Variables

  1. #1
    Join Date
    Dec 1969

    Default Losing Global Variables

    I&#039;ve declared two global variables using C# as follows:<BR><BR>//set global string variables to hold SponsorID and DeductAmount<BR>int SponsorID, DeductAmount;<BR><BR>I then set these variables in my Page_Load event handler, using SQL Output parameters:<BR><BR>SponsorID = Convert.ToInt32(parameterSponsorID.Value); <BR>DeductAmount = Convert.ToInt32(parameterAmount.Value);<BR><BR>I&# 039;ve confirmed that these values are assigned on the Page_Load. However, when I click the Submit button and use these global variables in my UPDATE statement they revert to 0. What am I doing wrong here?<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Losing Global Variables

    Variables that are declared globally and assigned in the page load exist when that page is first processed on the server. They are used within your logic to determine how to render the page that is displayed. When the submit button is clicked, the variables no longer exist. In order to persist variables through page postbacks (i.e. submits) you must store them in the Session object (memory in the server associated with the session) or in a cookie. You can also declare hidden text fields and place the values in there, or have them participate in the StateBasket.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts