Share variable across site ASP.NET
Posted
by Anders
on Stack Overflow
See other posts from Stack Overflow
or by Anders
Published on 2008-11-06T14:07:09Z
Indexed on
2010/03/27
20:43 UTC
Read the original article
Hit count: 151
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.
© Stack Overflow or respective owner