Page Level Variable (C#)
<%@ Page Language="C#" Debug="true" %> <script runat="server"> string strVariableGlobal = "Variable Global: Use me anyplace on the page"; void Page_Load() { string strMyVariable1 = "Block Variable Used In Block"; if (1==1) { string strMyVariable2 = "Block Variable Used In Block"; string strMyVariable3 = "Block Variable Used After Block"; lblMessageBlockInBlock.Text = strVariableGlobal; } lblMessageProcedure.Text = strVariableGlobal; SubProcedure2(); } void SubProcedure2() { lblMessageBlockOutBlock.Text = strVariableGlobal; } </script> <html> <head> <title>Variable Scope</title> </head> <body> <form runat="server"> <asp:Label id="lblMessageBlockInBlock" runat="server" text="DEFAULT - BlockInBlock"/> <br /> <asp:Label id="lblMessageBlockOutBlock" runat="server" text="DEFAULT - BlockOutBlock"></asp:Label> <br /> <asp:Label id="lblMessageProcedure" runat="server" text="DEFAULT - Procedure"></asp:Label> <br /> </form> </body> </html>