Function Level variables (C#) : Variable Scope « Language Basics « ASP.Net






Function Level variables (C#)

<%@ Page Language="C#" Debug="true" %>
<script runat="server">

    void Page_Load()
    {
      string strMyFuncVariable = "Function-Level Variable";
      if(Page.IsPostBack)
      {
          string strMyBlockVariableUsedInside = "Block Variable Used In Block";
          lblMessageBlockInBlock.Text = strMyBlockVariableUsedInside;
          lblMessageFunction.Text = strMyFuncVariable;
      }
    
    }

</script>
<html>
<head>
    <title>Variable Scope</title>
</head>
<body>
    <form runat="server">
        <asp:Label id="lblMessageBlockInBlock" runat="server" text="DEFAULT - BlockInBlock"></asp:Label>
        <br />
        <asp:Label id="lblMessageFunction" runat="server" text="DEFAULT - Function"></asp:Label>
        <br />
        <asp:Button id="Button1" runat="server" Text="Submit"></asp:Button>
    </form>
</body>
</html>

           
       








Related examples in the same category

1.Local variable inside a function (VB.net)
2.Page level variable and function level variable (VB.net)
3.Define page level variables (VB.net)
4.Page Level Variable (C#)
5.block-level variables (C#)