什么是PostBack(译) What is a postback?

下面的内容是针对ASP.NET新手的

PostBack什么时候被引发?

PostBack由客户端浏览器引发。通常是用户操作(点击按钮、修改下拉框等)页面中的某个控件,然后该控件发起一个PostBack。最后该控件的状态加上本页面上所有的其它控件(也就是ViewState)一起回发到服务器。

PostBack时发生了什么?

通常情况下PostBack会触发web服务器创建一个被引发了PostBack的页面page类的实例。然后这个page对象就步入了它常规的页面生命周期,与一般情况稍有差异(见下文)。如果你没有在页面的生命周期内将用户重定向到另一个指定的页面,PostBack的最终结果将是再次将相同的页面呈现给用户,然后开始等待下一个PostBack。

为什么需要PostBack?

web应用是运行在web服务器上的。为了处理用户请求所导致的应用状态的更改或是页面的跳转,你需要一些在web服务器上运行的代码。实现该目标的唯一方法就是收集用户正在使用的所有信息,然后将它们发回到服务器。

一些新手应该注意的事情

  • 控件的状态在回发页的环境中是可用的。通过这些信息你可以在后台操作页面控件或是重定向到其它页面。
  • WebForm里面的控件包含events(事件)、event handlers(事件处理器),页面生命周期的初始化部分将在引发PostBack的控件的后台事件被调用前执行。即当用户点击按钮时,会先执行Page Init和Load事件再执行按钮单击事件。
  • 页面PostBack(回发)时,属性“Page.IsPostBack”的值为“true”,其它情况(例如页面初次载入)为“false”。
  • Ajax和MVC技术修改了PostBack的工作模式。

The following is aimed at beginners to ASP.Net...

When does it happen?

A postback originates from the client browser. Usually one of the controls on the page will be manipulated by the user (a button clicked or dropdown changed, etc), and this control will initiate a postback. The state of this control, plus all other controls on the page,(known as the View State) isPosted Back to the web server.

What happens?

Most commonly the postback causes the web server to create an instance of the code behind class of the page that initiated the postback. This page object is then executed within the normal page lifecycle with a slight difference (see below). If you do not redirect the user specifically to another page somewhere during the page lifecycle, the final result of the postback will be the same page displayed to the user again, and then another postback could happen, and so on.

Why does it happen?

The web application is running on the web server. In order to process the user’s response, cause the application state to change, or move to a different page, you need to get some code to execute on the web server. The only way to achieve this is to collect up all the information that the user is currently working on and send it all back to the server.

Some things for a beginner to note are...

  • The state of the controls on the posting back page are available within the context. This will allow you to manipulate the page controls or redirect to another page based on the information there.
  • Controls on a web form have events, and therefore event handlers, just like any other controls. The initialisation part of the page lifecycle will execute before the event handler of the control that caused the post back. Therefore the code in the page’s Init and Load event handler will execute before the code in the event handler for the button that the user clicked.
  • The value of the “Page.IsPostBack” property will be set to “true” when the page is executing after a postback, and “false” otherwise.
  • Technologies like Ajax and MVC have changed the way postbacks work.

什么是PostBack(译)的更多相关文章

  1. 支持行单击、双击事件的GridView和DataList控件(译)

    支持行单击.双击事件的GridView和DataList控件(译)         让GridView 和 DataList 控件响应鼠标单击.双击事件.并且,使用 ClientScript.Regi ...

  2. RxJS + Redux + React = Amazing!(译一)

    今天,我将Youtube上的<RxJS + Redux + React = Amazing!>翻译(+机译)了下来,以供国内的同学学习,英文听力好的同学可以直接看原版视频: https:/ ...

  3. Entity Framework 6 Recipes 2nd Edition 译 -> 目录 -持续更新

    因为看了<Entity Framework 6 Recipes 2nd Edition>这本书前面8章的翻译,感谢china_fucan. 从第九章开始,我是边看边译的,没有通读,加之英语 ...

  4. RxJS + Redux + React = Amazing!(译二)

    今天,我将Youtube上的<RxJS + Redux + React = Amazing!>的后半部分翻译(+机译)了下来,以供国内的同学学习,英文听力好的同学可以直接看原版视频: ht ...

  5. 「译」JUnit 5 系列:条件测试

    原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...

  6. CSharpGL(31)[译]OpenGL渲染管道那些事

    CSharpGL(31)[译]OpenGL渲染管道那些事 +BIT祝威+悄悄在此留下版了个权的信息说: 开始 自认为对OpenGL的掌握到了一个小瓶颈,现在回头细细地捋一遍OpenGL渲染管道应当是一 ...

  7. [译]基于GPU的体渲染高级技术之raycasting算法

    [译]基于GPU的体渲染高级技术之raycasting算法 PS:我决定翻译一下<Advanced Illumination Techniques for GPU-Based Volume Ra ...

  8. Entity Framework 6 Recipes 2nd Edition(9-4)译->Web API 的客户端实现修改跟踪

    9-4. Web API 的客户端实现修改跟踪 问题 我们想通过客户端更新实体类,调用基于REST的Web API 服务实现把一个对象图的插入.删除和修改等数据库操作.此外, 我们想通过EF6的Cod ...

  9. Entity Framework 6 Recipes 2nd Edition(10-1)译->非Code Frist方式返回一个实体集合

    存储过程 存储过程一直存在于任何一种关系型数据库中,如微软的SQL Server.存储过程是包含在数据库中的一些代码,通常为数据执行一些操作,它能为数据密集型计算提高性能,也能执行一些为业务逻辑. 当 ...

随机推荐

  1. SpringMVC源码之参数解析绑定原理

    摘要 本文从源码层面简单讲解SpringMVC的参数绑定原理 SpringMVC参数绑定相关组件的初始化过程 在理解初始化之前,先来认识一个接口 HandlerMethodArgumentResolv ...

  2. SqlServer循环 和 批量倒数据

    SqlServer循环语句 declare @i int set @i =1 while(@i<5) begin  set @i = @i+1  insert into text(id,name ...

  3. chrome无法登陆账号,显示操作超时的解决方案

    起因 今天重装了下windows操作系统,准备登陆chrome浏览器,以同步各种插件(你懂的),结果是...无法登陆账号,显示操作超时,真是无语了. 碰到了这个问题第一个直觉是:FQ.突然想到如果修改 ...

  4. spring使用中问题汇总

    1.配置文件找不到beans元素:可能是xsd与spring版本不一致,导致无法效验: 解决方案:将applicationContext.xml中xsd文件定义的版本改为spring jar包中定义的 ...

  5. qt事件机制---事件范例

    在笔记qt课程04笔记中

  6. iOS实现微信外部H5支付完成后返回原APP

    看到微信最近放开了微信H5支付,公司决定把H5集成到多款APP上.下面记录下了开发过程. 由于是微信新推出的支付方式,在网上搜索到的相关资料并不多,其中有一篇文件(点此跳转)对我的整个开发过程起到了很 ...

  7. jq实现数字增加或者减少的动画

    效果图: 1.HTML: <div class="up"></div> <br> <div class="down"& ...

  8. MIPS中有关于分支指令及跳转寻址

    分支指令 分支指令包含该指令,和两个操作数,以及跳转的分支地址,该地址是相对于下一条指令的相对地址 分支指令占6位   操作数1占5位     操作数2占5位     分支指令16位 例如 bne  ...

  9. Docker镜像的构成__docker commit

    镜像是容器的基础,每次执行docker run的时候都会制定哪个镜像作为容器运行的基础.在之前的例子中,我们所使用的都来自于Docker Hub的镜像.直接使用这些镜像是可以满足一定的需求,而当这些镜 ...

  10. 理解 Git

    Git 如何保存文件 其它版本管理系统通常会保存所有文件及其历次提交的差异(diff / revision),通过 merge 原始文件与各阶段的差异就能获取任何版本的状态 而 Git 保存的是每一次 ...