linux社区爱心援助Linux认证系列教程业界动态站务新闻公司招聘网络学院网址大全LPI专题CISCO专题
设为首页
加入收藏
管理团队
JSP  
JAVA  
PERL  
 您的位置:首页 > 开发语言 > asp.net >
栏目导栏
  php
  JSP
  ASP
  asp.net
  JAVA
  c/c++/c#
  perl
  JavaScript
  Basic
  Delphi
资料搜索
热门文章
·NetBPM工作流的一个示例:请假
·Office Web Components(OWC)绘
·asp.net正则表达式语法
·asp.net 2.0 ajax中使用PopupC
·Ado.Net读取Excel常见问题总结
·数据源为空时如何让GridView显
·如何让UpdatePanel支持文件上传
·C#.Net的常见面试试题和参考答
·asp.net ajax客户端编程+jquer
·Brettle.Web.NeatUpload.dll支
·ASP.NET使用Cookie
·ASP.NET DEMO 15: 同时支持行单
·如何使IE的后退按钮无效
·如何在ASP.NET中用OWC绘制图表
·asp.net:正确判断当前用户角色
最新文章
·Ajax Control Toolkit Animati
·讨论一下类似BlogEngine内一次
·使用CSS+SiteMap+UserControl+
·Asp.net中多彩下拉框的实现
·浅谈ASP.NET的Postback
·分清ASP.NET AJAX中的Extender
·Tip:在使用AjaxControlTookit
·有关注册DataItem的一些可能被
·IIRF(Ionic's Isapi Rewrite
·asp.net 客户端回调功能的实现
·关于控件部分的看法--读Progra
·为什么在vista上做开发
·如何封装JS和CSS文件为服务器端
·岂今我看过的最强的排序算法
·设计模式学习笔记之单件模式
Google
 
Asp.net Ajax 1.0 异步回调时,服务器端Render原理1
[ 作者:  加入时间:2007-11-20 15:19:45  来自:Linux联盟收集整理 ]
首冼回顾一下 3cjLinux联盟
  Page页的生命周期 3cjLinux联盟
   3cjLinux联盟
  PreInit 3cjLinux联盟
  Init 3cjLinux联盟
  InitComplete 3cjLinux联盟
  LoadState 3cjLinux联盟
  ProcessPostData 3cjLinux联盟
  PreLoad 3cjLinux联盟
  Load 3cjLinux联盟
  LoadComplete 3cjLinux联盟
  PreRender 3cjLinux联盟
  PrepareCallback //如果有回调 3cjLinux联盟
  PreRenderComplete 3cjLinux联盟
  SaveState 3cjLinux联盟
  SaveStateComplete 3cjLinux联盟
  Render 3cjLinux联盟
   3cjLinux联盟
  不论是Asp.net请求,还是Ajax请求,都要执行上面的页生命周期, 3cjLinux联盟
   3cjLinux联盟
  在Page页最后会调用Page.RenderControl()呈现Page所有子控件 3cjLinux联盟
   3cjLinux联盟
  流程如下 3cjLinux联盟
   3cjLinux联盟
  Page.RenderControl 3cjLinux联盟
   Control.RenderControl() 3cjLinux联盟
   Control.RenderControl(writer,this.Adapter) 3cjLinux联盟
   Control.RenderControlInternal() 3cjLinux联盟
   Control.Render() //此时Page.Render()将其重写 3cjLinux联盟
   Control.RenderChildren() 3cjLinux联盟
   Control.RenderControlInternal() 3cjLinux联盟
   3cjLinux联盟
  现在关键所在 3cjLinux联盟
  Control.RenderControlInternal()实现如下 3cjLinux联盟
  如果不是Asp.net Ajax处理,肯定会执行foreach依次对所有的子控件进行遍历 3cjLinux联盟
   3cjLinux联盟
   internal void RenderChildrenInternal(HtmlTextWriter writer, ICollection children) 3cjLinux联盟
   { 3cjLinux联盟
   //正常情况如果不设置RareFields,进行默认的流程依次对所有子控件进行处理, 3cjLinux联盟
   //如果设置RareFields,意思就是以自定义的方式改写RenderChildren 3cjLinux联盟
   if ((this.RareFields != null) && (this.RareFields.RenderMethod != null)) //当您SetRenderMethodDelegate时,RareFieldsEnsured就有值啦 3cjLinux联盟
   { 3cjLinux联盟
   writer.BeginRender(); 3cjLinux联盟
   3cjLinux联盟
   //调用RenderMethod委托,Asp.net Ajax1.0在使用Control.SetRenderMethodDelegate时,对应的回调函数就是在此时处理的 3cjLinux联盟
   this.RareFields.RenderMethod(writer, this); 3cjLinux联盟
   writer.EndRender(); 3cjLinux联盟
   } 3cjLinux联盟
   else if (children != null) 3cjLinux联盟
   { 3cjLinux联盟
   //如果不设置这个RareFieldsEnsured,会把Page里所有的控件呈现 3cjLinux联盟
   //依次调用Control里所有子控件的RenderControl 3cjLinux联盟
   foreach (Control control in children) 3cjLinux联盟
   { 3cjLinux联盟
   control.RenderControl(writer); 3cjLinux联盟
   } 3cjLinux联盟
   } 3cjLinux联盟
   3cjLinux联盟
  } 3cjLinux联盟
   3cjLinux联盟
  以上是Asp.net 的Render处理 3cjLinux联盟
  肯定有人要问上面的if是干吗的,这个可是微软流的接口呀,整个asp.net ajax全靠这个接口进行处理 3cjLinux联盟
   3cjLinux联盟
  在Asp.netAjax1.0上,你肯定要放一个ScriptManager吧 3cjLinux联盟
  它也是Control的子类, 3cjLinux联盟
  在Page生命周期的OnPreRender时,它会调用 3cjLinux联盟
   3cjLinux联盟
  PageRequestManager.OnPreRender(); 3cjLinux联盟
   3cjLinux联盟
   3cjLinux联盟
  问题就在这,PageRequestManager.OnPreRender()实现如下 3cjLinux联盟
   3cjLinux联盟
  _owner.IPage.SetRenderMethodDelegate(RenderPageCallback); 3cjLinux联盟
   3cjLinux联盟
  SetRenderMethodDelegate()方法是干什么用的 3cjLinux联盟
   3cjLinux联盟
  在Control中,当您调用了SetRenderMethodDelegate会给Control.RareFieldsEnsured设置值 3cjLinux联盟
   public void SetRenderMethodDelegate(RenderMethod renderMethod) 3cjLinux联盟
   { 3cjLinux联盟
   //使用OccasionalFields.RareField 3cjLinux联盟
   this.RareFieldsEnsured.RenderMethod = renderMethod; 3cjLinux联盟
   this.Controls.SetCollectionReadOnly("Collection_readonly_Codeblocks"); 3cjLinux联盟
   } 3cjLinux联盟
   3cjLinux联盟
  到这一切就清晰了,当您设置了RenderPageCallback,正常的Asp.net流程就不会再走了,所有的子控件就不会被Render 3cjLinux联盟
  在Asp.netAjax 1.0中使用 3cjLinux联盟
   3cjLinux联盟
  private void RenderPageCallback(HtmlTextWriter writer, Control pageControl) 3cjLinux联盟
  { 3cjLinux联盟
   ... 3cjLinux联盟
   //取出当前的HtmlForm 3cjLinux联盟
   IHtmlForm formControl = _owner.IPage.Form; 3cjLinux联盟
   3cjLinux联盟
   //手动设置当FormControl.RenderControl时()回调方法 ,因为这个时候Page.Controls里有子控件不会被Render啦,怎么办 3cjLinux联盟
   //手动处理一个呗 3cjLinux联盟
   formControl.SetRenderMethodDelegate(RenderFormCallback); 3cjLinux联盟
   3cjLinux联盟
   //同样,HtmlForm.RenderControl不会在Page.Controls里自动触发的 3cjLinux联盟
   //这个时候您需要手动的RenderCtronl一下,这样才能调用RenderFormCallback 3cjLinux联盟
   formControl.RenderControl(formWriter); 3cjLinux联盟
Linux联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
无相关信息