Global variable not keeping value

  • Thread starter Thread starter tfs
  • Start date Start date
T

tfs

I have a variable I am trying to keep the values in and I have it set
as a global variable.

<script runat="server">

Dim saveCommandText as String

Sub SortDataGrid (sender as Object, e as
DataGridSortCommandEventArgs)

response.Write("Before setting saveCommandText = "
& saveCommandText & "<p>")
If saveCommandText = "" then
saveCommandText = DataSet1.CommandText
End if
response.Write("After setting saveCommandText = " &
saveCommandText & "<p>")
DataSet1.CommandText = saveCommandtext & " order by
" & e.SortExpression

end Sub
</script>


saveCommandText gets set, but when I go to SortDataGrid after a button
is pushed, saveCommandText is blank again.

Why is this? Doesn't the system keep these variables values?

Thanks,

Tom.
 
tfs said:
I have a variable I am trying to keep the values in and I have it set
as a global variable.

<script runat="server">

Dim saveCommandText as String
[snip]


This variable is global (meaning: available in all subs and functions)
for *this instance* of this page. As soon as the request is
finished, the variable becomes unavailable.

If you want this value to be available to the entire application (every user
sees the same value), store it in the Application object.
If every user should have his/her own value, use Session.

Hans Kesting
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top