I have a class isSearching with a single boolean property in a ‘functions’ file in my webapp. On my search page, I have a variable oSearchHandler declared as a Public Shared variable. How can I access the contents of oSearchHandler on other pages in my webapp?
Code with Session….
'search.aspx Public Function oSearchString(ByVal oTextBoxName As String) As String For Each oKey As String In Request.Form.AllKeys If oKey.Contains(oTextBoxName) Then Session.Add('searching', True) Session.Add('search-term', Request.Form(oKey)) Return Request.Form(oKey) End If Next Return '' End Function 'theMaster.master <% If Session('searching') Then %><ul style='float: right;'> <li> <div class='gsSearch'> <asp:TextBox ID='searchbox' runat='server'></asp:TextBox> </div> </li> <li> <div class='gsSearch'> <asp:Button ID='searchbutton' runat='server' Text='search' UseSubmitBehavior='true' PostBackUrl='search.aspx' CssClass='searchBtn' /> </div> </li> </ul> <% End If %>
I think that the session will work just fine.
If you’re talking about accessing these variables between page interactions, you need to bear in mind that the state is discarded between pages.
Instead, you need to store this data in Session State.
If it’s not across page interactions, but simply accessing the data from other parts of the code, the key is that the ASP.NET page becomes a class and your public shared variable, a static property of that class.
So, you’d access it from elsewhere using PageName.oSearchHandler
[EDIT] Can you give us some more information about what oSearchHandler is and how you’re intending using it? We can probably offer a more considered recommendation, then.