I am new to ASP.NET so I appreciate any help you can offer.
I am trying to develop some common variables, subroutines and functions to use in master pages and content pages in a new ASP.NET 2.0 website. I am developing in Visual Studio 2005 and am having a problem with variables declared in my namespace/class persisting between page reloads.
I have three files:
/App_Code/ns_common.vb file is listed below. It's quite a bit bigger than this, but this gives you the idea. I define a namespace "rzg", and the "common" class, and a global variable "NavBarTop" in this file:
Public Class common
Public Shared NavBarTop As String = ""
Public Shared Sub BuildNavigation()
' In this sub I open an XML file for data, loop
' through it and build the contents of the variable
' NavBarTop which is a site navigation bar for all
' pages at the website
/master_main.master is as follows. I am trying to display the navigation bar "NavBarTop" in this file and call the subroutine to generate it in the Page_Load subroutine:
<%@ Master Language="VB"%>
Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
/test_master.aspx is basically just an empty file right now for testing:
<%@ Page Language="VB" MasterPageFile="~/master_m
" Title="Untitled Page" Trace="true"%>
<asp:Content ID="Content1" ContentPlaceHolderID="Cont
I am not using code behind pages.
This seems to let me share my code (variables, subroutines and functions) between pages, but each time I refresh or reload the test_master.aspx file in my browser (IE) it keeps appending the value of NavBarTop to itself. I read somewhere that Public Shared variables persist between trips to the server, and this certainly seems to be the case.
Is there a better way to do this?
Is there a way to stop the NavBarTop from growing between page reloads?