ASP.Net/Asp Control/Reset Button

Материал из .Net Framework эксперт
Версия от 11:53, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Reset the form

<%@ Page Language="VB" %>
<script runat="server">
    Sub Reset()
    
      Textbox1.Text = ""
      Textbox2.Text = "0"
    
    End Sub
    
    Sub Page_Load(sender As Object, e As EventArgs)
    
      If Not Page.IsPostback
        Reset()
      End If
    
    End Sub
    
    Sub btnSubmit_Click(sender As Object, e As EventArgs)
    
      If cint(textbox2.text) < 20 Then
    
        label1.text = "Hi " & textbox1.text & ", you are " & textbox2.text & ", which is young!"
    
      Else If cint(textbox2.text) < 40 Then
      
        label1.text = "Hi " & textbox1.text & ", you are " & textbox2.text & ", which means you"re middle-aged!"
    
      Else 
    
        label1.text = "Hi " & textbox1.text & ", you"re old!"
    
      End If
    
    End Sub
    
    Sub btnReset_Click(sender As Object, e As EventArgs)
    
      Reset()
    
    End Sub
</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <p>
            Enter your name: 
            <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
        </p>
        <p>
            Enter you age: 
            <asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
        </p>
        <p>
            <asp:Button id="btnSubmit" onclick="btnSubmit_Click" runat="server" Text="Submit"></asp:Button>
            &nbsp; 
            <asp:Button id="btnReset" onclick="btnReset_Click" runat="server" Text="Reset"></asp:Button>
        </p>
        <p>
            <asp:Label id="Label1" runat="server"></asp:Label>
        </p>
    </form>
</body>
</html>