ASP.Net/Page/Postback

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

Demonstration of IsPostBack property (VB.net)

<% @Page Language="vb" %>
<html>
<head>
<title>IsPostBack Demonstration</title>
<script runat="server" >
   Sub Page_Load(Sender As Object, e As EventArgs)
      If Not IsPostBack Then
         lblMessage.Text = "Before PostBack" 
      Else
         lblMessage.Text = "Posted Back" 
      End If
   End Sub
</script>
</head>
<body> 
   <h1>Demonstration of IsPostBack property</h1>
   <form id="frmPostBack" runat="server">
      <asp:label id="lblMessage" runat="server"/>
      <asp:Button type="Submit" text="Post Back" runat="server"/>
   </form>
</body>
</html>



Page IsPostBack Demo (C#)

<%@ Page Language="C#" Debug="true" %>
<script runat="server">
void Page_Load(){
   if (Page.IsPostBack){
       string[] choice = new string[3];
       choice[0] = "1";
       choice[1] = "2";
       choice[2] = "3";
       lblShipper.Text = "Shipper ID for " + txtShipNum.Text + " is " + Array.IndexOf(choice, txtShipNum.Text);
       lblShipper.Visible = true;
   }
}
</script>
<html>
<head>
    <title>Array Example</title>
</head>
<body>
    <form runat="server">
        Please enter your shipper name. 
        (should be "1"  or  "2"  or  "3") 
        <br><asp:TextBox id="txtShipNum" runat="server" width="300px"></asp:TextBox>
        <br />
        Press button to find the Shipper ID number
        <asp:Button id="Button1" runat="server" Text="Submit"></asp:Button>
        <br />
        <asp:Label id="lblShipper" runat="server"></asp:Label>
    </form>
</body>
</html>



Page.IsPostBack Property (VB.net)

<%@ Page Language="vb" %>
<html>
   <head>
      <title>IsPostBack property example</title>
      <script runat="server">
         Sub Page_Load()
            If Page.IsPostBack Then
               Message.Text = "PostBack"
            Else
               Message.Text = "Non-PostBack"
            End If
         End Sub
      </script>
   </head>
<body>
   <form runat="server">
      <asp:button id="post" Text="Post page" runat="server"/>
      <asp:label id="Message" runat="server"/>
   </form>
</body>
</html>