什么是真正的IsPostBack意思? [英] What does IsPostBack actually mean?

查看:135
本文介绍了什么是真正的IsPostBack意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道具体是什么意思Page.IsPostBack。我充分意识到它的一天在一个标准的ASP.NET页面的日常使用,这表明用户是
数据提交到服务器侧。请参见页:IsPostBack属性

I am interested to know what specifically Page.IsPostBack means. I am fully aware of it's day to day use in a standard ASP.NET page, that it indicates that the user is submitting data back to the server side. See Page:IsPostBack Property

但是,鉴于此HTML

But given this HTML

<html>
   <body>
      <form method="post" action="default.aspx">
         <input type="submit" value="submit" />
      </form>
   </body>
</html>

在提交按钮点击,页面的Page_Load方法被调用,但Page.IsPostBack是返回false。我不希望添加 RUNAT =服务器

When clicking on the Submit button, the pages Page_Load method is invoked, but the Page.IsPostBack is returning false. I don't want to add runat=server.

我如何告诉第一页负载之间的差异,以及由客户端点击提交引起的请求?

How do I tell the difference between the pages first load, and a Request caused by the client hitting submit?

更新

INPUT TYPE =文本值=AANAME =CTRLID =CTRL/&GT; 这样的Request.Form有我在℃加入一个元素,Request.HTTPMethod是POST,但的IsPostBack还是假的?

update
I've added in <input type="text" value="aa" name="ctrl" id="ctrl" /> so the Request.Form has an element, and Request.HTTPMethod is POST, but IsPostBack is still false?

推荐答案

要做到这一点的方法之一是扩展ASP.NET Page类,覆盖IsPostBack属性,让所有网页的扩展页面中获得。

One way to do this is to extend the ASP.NET Page class, "override" the IsPostBack property and let all your pages derive from the extended page.

public class MyPage : Page
{
    public new bool IsPostBack
    {
        get 
        { 
          return 
            Request.Form.Keys.Count > 0 &&
            Request.RequestType.Equals("POST", StringComparison.OrdinalIgnoreCase); 
         }
    }
}

这篇关于什么是真正的IsPostBack意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆