⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demo-if.aspx

📁 asp.net1.1入门经典C#.2003
💻 ASPX
字号:
<%@ Page Language="C#" Debug="true" %>
<script runat="server">

    void page_Load()
         {
              if(Page.IsPostBack)
              {
    // Clean up from prior tests
    lblFax.Text = "";
    lblTel.Text="";
    txtTel.Visible=false;
    // end Clean up from prior tests
    
    
    // if syntax option #1
    // Only have actions if expression is true
    // and only one line of action
    if (chkFaxConfirm.Checked == true) lblFax.Text = "We will confirm by fax.";
    
    // if syntax option #2
    // Only have actions if expression is true
    // multiple lines of action
    if (chkTelConfirm.Checked == true)
        {
        lblTel.Text = "We will confirm by telephone. Please enter your number";
        txtTel.Visible =true;
        }
    
    
    // if syntax option #3
    if (chkShipByGovernment.Checked == true)
        {
        lblAddress.Text = "Please enter your post office box number";
        txtAddress.Visible=true;
        }
    else
        {
        lblAddress.Text = "Please enter your street address";
        txtAddress.Visible=true;
        }
    
    // if syntax option #3 alternate - Tenary form
    // one comand each for true and false conditions
       lblCustomsFormRequired.Text=(chkCustomsFormRequired.Checked == true ? "We will provide a customs form" : "We will not fill in a customs form");
    
    
    // if syntax option #4
    
        if(chkIsMember.Checked==true)
        {
        lblOut.Text = "Members get free handling";
        lblOut.BackColor=System.Drawing.Color.LightPink;
        }
        else if(Convert.ToInt32(txtAge.Text)<=18)
        {
        lblOut.Text = "Handling fee for students = ¥300";
        lblOut.BackColor=System.Drawing.Color.LightCyan;
        }
        else
        {
        lblOut.Text = "Price is ¥500";
        lblOut.BackColor=System.Drawing.Color.LightSeaGreen;
        }   //end else of if stack of syntax option #4
      }   //end if(Page.IsPostBack)
    
    }   //end page_Load()

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <asp:Button id="Button1" runat="server" Text="Submit for all syntaxes"></asp:Button>
        <hr />
        <h3>if syntax option #1 
        </h3>
        Fax Confirm? 
        <asp:CheckBox id="chkFaxConfirm" runat="server" Checked="false"></asp:CheckBox>
        <asp:Label id="lblFax" runat="server"></asp:Label>
        <br />
        <hr />
        <h3>if syntax option #2 
        </h3>
        Telephone Confirm? 
        <asp:CheckBox id="chkTelConfirm" runat="server" Checked="false"></asp:CheckBox>
        <asp:Label id="lblTel" runat="server"></asp:Label>
        <asp:TextBox id="txtTel" runat="server" Visible="false"></asp:TextBox>
        <hr />
        <h3>if syntax option #3 
        </h3>
        Ship by Government Post? 
        <asp:CheckBox id="chkShipByGovernment" runat="server" Checked="false"></asp:CheckBox>
        <asp:Label id="lblAddress" runat="server"></asp:Label>
        <asp:TextBox id="txtAddress" runat="server" Visible="false"></asp:TextBox>
        <br />
        <hr />
        <h3>if syntax option #3 - alternate form - Ternary 
        </h3>
        International customs form required? 
        <asp:CheckBox id="chkCustomsFormRequired" runat="server" Checked="false"></asp:CheckBox>
        <asp:Label id="lblCustomsFormRequired" runat="server"></asp:Label>
        <br />
        <hr />
        <h3>if syntax option #4 
        </h3>
        Please answer questions below to calculate your handling charge<br />
        Members = free Students = ¥300 Others = ¥500 <br />
        Your age = <asp:TextBox id="txtAge" runat="server" width=40></asp:TextBox>&nbsp;&nbsp;&nbsp;
        Are you a member (check means yes)? <asp:CheckBox id="chkIsMember" runat="server"></asp:CheckBox><br>
        Your handling charge is:
        <asp:Label id="lblOut" runat="server"><br /></asp:Label>

        
    </form>
</body>
</html>

⌨️ 快捷键说明

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