tio-variablescope2.aspx

来自「asp.net1.1入门经典C#.2003」· ASPX 代码 · 共 35 行

ASPX
35
字号
<%@ 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";
        string strMyBlockVariableUsedOutside= "Block Variable Used After Block";
        lblMessageBlockInBlock.Text = strMyBlockVariableUsedInside;
        lblMessageFunction.Text = strMyFuncVariable;
      }   // end if(postback)
          // note - block variables now out of scope
      lblMessageBlockOutBlock.Text = strMyBlockVariableUsedOutside;
    }   // End page_load

</script>
<html>
<head>
    <title>Variable Scope</title>
</head>
<body>
    <form runat="server">
        <asp:Label id="lblMessageBlockInBlock" runat="server" text="DEFAULT -&#13;&#10;     BlockInBlock"></asp:Label>
        <br />
        <asp:Label id="lblMessageBlockOutBlock" runat="server" text="DEFAULT -&#13;&#10;     BlockOutBlock "></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>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?