码迷,mamicode.com
首页 > 其他好文 > 详细

010-判断是否回传IsPostBack属性

时间:2017-01-14 23:16:09      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:asp   mit   isnull   ebe   输出   提交   str   oev   bsp   

属性IsPostBack:判断是否回传
如果是第一次请求,则返回false
如果是回传请求,则返回true
-》说明:只有使用服务器端表单才可以正常使用IsPostBack
-》使用情境:当在一个页面中,既写了第一次请求代码,也写了回传处理代码,则需要进行判断处理

 1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="t2_IsPostBack.Index" %>
 2 
 3 <!DOCTYPE html>
 4 
 5 <html xmlns="http://www.w3.org/1999/xhtml">
 6 <head runat="server">
 7 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 8     <title></title>
 9 </head>
10 <body>
11     <form id="form1" runat="server">
12     <div>
13         <%=Title1 %>
14     <input type="submit" name="sdxl" value="提交"/>
15     </div>
16     </form>
17 </body>
18 </html>
 1     public partial class Index : System.Web.UI.Page
 2     {
 3         protected string Title1 { get; set; }
 4         protected void Page_Load(object sender, EventArgs e)
 5         {
 6             //string sdxl = Request["sdxl"];
 7 
 8             //if (string.IsNullOrEmpty(sdxl))
 9             //{
10             //    //当第一次请求时,输出“小龙包”
11             //    Title1 = "小龙包";
12             //}
13             //else
14             //{
15             //    //Post-back:回传
16             //    //如果是点击按钮提交回来时,输出“杨过”
17             //    Title1 = "杨过";
18             //}
19 
20             //IsPostBack:用于判断页面是否回传,当回传时返回true,否则返回false
21             if (!IsPostBack)
22             {
23                 //第一次加载时执行
24                 Title1 = "小龙包";
25             }
26             else
27             {
28                 //回传加载
29                 Title1 = "杨过";
30             }
31         }
32     }

 

010-判断是否回传IsPostBack属性

标签:asp   mit   isnull   ebe   输出   提交   str   oev   bsp   

原文地址:http://www.cnblogs.com/ninghongkun/p/6286248.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!