ASP.NET调用UpdatePanel的Update()方法实例

本篇内容介绍了“ASP.NET调用UpdatePanel的Update()方法实例”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

公司主营业务:成都做网站、网站制作、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。成都创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。成都创新互联推出兖州免费做网站回馈大家。

ASP.NET中用编程的方法控制UpdatePanel的更新

UpdatePanel可以用来创建丰富的局部更新Web应用程序,它是ASP.NET 2.0 AJAX Extensions中很重要的一个控件。对于UpdatePanel,我们也可以使用编程的方法来控制它的更新,可以通过ScriptManager的RegisterAsyncPostBackControl()方法注册一个异步提交的控件,并且调用UpdatePanel的Update()方法来让它更新。再次用我在前面的文章中用到的一个无聊的时间更新例子来看一下,有时候我觉得例子过于复杂更加不好说明白所要讲的内容,如下代码所示,注意Button1并不包含在UpdatePanel中:

  1. <%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default
    .aspx.cs"Inherits="_Default"%> 

  2. <scriptrunatscriptrunat="server"> 

  3. voidButton1_Click(objectsender,EventArgse)  

  4. {  

  5. this.Label2.Text=DateTime.Now.ToString();  

  6. }  

  7. script> 

  8. <htmlxmlnshtmlxmlns="http://www.w3.org/1999/xhtml"> 

  9. <headrunatheadrunat="server"> 

  10. </strong>RefreshinganUpdatePanelProgrammatically<strong>title></strong> </p></li><li><p><strong>head></strong> </p></li><li><p><strong><body></strong> </p></li><li><p><strong><</strong>formid<strong>formid</strong>="form1"runat="server"<strong>></strong> </p></li><li><p><strong><</strong>asp:ScriptManagerID<strong>asp:ScriptManagerID</strong>="ScriptManager1<br/>"runat="server"<strong>/></strong> </p></li><li><p><strong><div></strong> </p></li><li><p><strong><</strong>asp:UpdatePanelID<strong>asp:UpdatePanelID</strong>="UpdatePanel1"runat=<br/>"server"UpdateMode="Conditional"<strong>></strong> </p></li><li><p><strong><ContentTemplate></strong> </p></li><li><p><strong><</strong>asp:LabelID<strong>asp:LabelID</strong>="Label1"runat="server"Text=<br/>"更新时间:"<strong>>asp:Label></strong> </p></li><li><p><strong><</strong>asp:LabelID<strong>asp:LabelID</strong>="Label2"runat="server"Text=<br/>"Label"ForeColor="Red"<strong>>asp:Label><br/><br/></strong> </p></li><li><p><strong>ContentTemplate></strong> </p></li><li><p><strong>asp:UpdatePanel></strong> </p></li><li><p><strong><</strong>asp:ButtonID<strong>asp:ButtonID</strong>="Button1"runat="server"Text=<br/>"Button"OnClick="Button1_Click"<strong>/></strong> </p></li><li><p><strong>div></strong> </p></li><li><p><strong>form></strong> </p></li><li><p><strong>body></strong> </p></li><li><p><strong>html></strong> </p></li></ol></pre><p>再次修改上面的例子,使用ScriptManager的RegisterAsyncPostBackControl()注册Button1为一个异步提交控件,并且调用UpdatePanel的Update()方法:</p><pre><ol><li><p><strong><</strong>%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"<br/>Inherits="_Default"%<strong>></strong> </p></li><li><p><strong><</strong>scriptrunat<strong>scriptrunat</strong>="server"<strong>></strong> </p></li><li><p>voidPage_Load(objectsender,EventArgse)  </p></li><li><p>{  </p></li><li><p>ScriptManager1.RegisterAsyncPostBackControl(Button1);  </p></li><li><p>}  </p></li><li><p>voidButton1_Click(objectsender,EventArgse)  </p></li><li><p>{  </p></li><li><p>this.Label2.Text=DateTime.Now.ToString();  </p></li><li><p>this.UpdatePanel1.Update();  </p></li><li><p>}  </p></li><li><p><strong>script></strong> </p></li><li><p><strong><</strong>htmlxmlns<strong>htmlxmlns</strong>="http://www.w3.org/1999/xhtml"<strong>></strong> </p></li><li><p><strong><</strong>headrunat<strong>headrunat</strong>="server"<strong>></strong> </p></li><li><p><strong><title></strong>RefreshinganUpdatePanelProgrammatically<strong>title></strong> </p></li><li><p><strong>head></strong> </p></li><li><p><strong><body></strong> </p></li><li><p><strong><</strong>formid<strong>formid</strong>="form1"runat="server"<strong>></strong> </p></li><li><p><strong><</strong>asp:ScriptManagerID<strong>asp:ScriptManagerID</strong>="ScriptManager1"runat="server"<strong>/></strong> </p></li><li><p><strong><div></strong> </p></li><li><p><strong><</strong>asp:UpdatePanelID<strong>asp:UpdatePanelID</strong>="UpdatePanel1"runat=<br/>"server"UpdateMode="Conditional"<strong>></strong> </p></li><li><p><strong><ContentTemplate></strong> </p></li><li><p><strong><</strong>asp:LabelID<strong>asp:LabelID</strong>="Label1"runat="server"Text="更新时间:"<strong>>asp:Label></strong> </p></li><li><p><strong><</strong>asp:LabelID<strong>asp:LabelID</strong>="Label2"runat="server"Text="Label"ForeColor<br/>="Red"<strong>>asp:Label><br/><br/></strong> </p></li><li><p> </p></li><li><p><strong>ContentTemplate></strong> </p></li><li><p><strong>asp:UpdatePanel></strong> </p></li><li><p><strong><</strong>asp:ButtonID<strong>asp:ButtonID</strong>="Button1"runat="server"Text=<br/>"Button"OnClick="Button1_Click"<strong>/></strong> </p></li><li><p><strong>div></strong> </p></li><li><p><strong>form></strong> </p></li><li><p><strong>body></strong> </p></li><li><p><strong>html></strong> </p></li></ol></pre><p>“ASP.NET调用UpdatePanel的Update()方法实例”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!</p> <br> 网站栏目:ASP.NET调用UpdatePanel的Update()方法实例 <br> 网页路径:<a href="http://bzwzjz.com/article/isjsho.html">http://bzwzjz.com/article/isjsho.html</a> </div> </div> <div class="other"> <h3>其他资讯</h3> <ul> <li> <a href="/article/pgoesd.html">云服务器与云虚拟主机有什么区别</a> </li><li> <a href="/article/pgoedh.html">使用linux的postconf命令显示main.cf配置参数的值</a> </li><li> <a href="/article/pgoeoc.html">R语言统计入门(第2版)</a> </li><li> <a href="/article/pgoech.html">访问phpmyadmin输入帐号密码无反应出错的解决方法</a> </li><li> <a href="/article/pgoesj.html">J2EE体系架构设计中值对象、传输对象、截取过滤器的示例分析</a> </li> </ul> </div> </div> <div class="footer2"> Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号 <br />友情链接: <a href="http://www.cxjianzhan.com/" target="_blank">网站制作公司 </a><a href="http://www.cxhlcq.com/qiye/" target="_blank">重庆企业网站建设 </a><a href="http://www.cqcxhl.com/" target="_blank">重庆网站建设 </a><a href="http://m.cdcxhl.cn/seo/" target="_blank">成都网站建设 </a><a href="http://m.xwcx.net/" target="_blank">H5网站制作 </a><a href="http://m.cdcxhl.com/liucheng.html" target="_blank">成都网站建设流程 </a><a href="http://chengdu.cdcxhl.cn/H5/" target="_blank">成都响应式网站建设公司 </a><a href="https://www.cdxwcx.com/" target="_blank">网站建设 </a><a href="http://www.cdxwcx.cn/sheji/" target="_blank">网站设计公司 </a><a href="http://chengdu.cdcxhl.com/" target="_blank">成都网站制作 </a><a href="http://www.cxjianzhan.com/" target="_blank">成都网站建设公司 </a><a href="http://www.33260.cn/" target="_blank">成都定制网站建设 </a><a href="http://chengdu.cdcxhl.com/" target="_blank">成都网站建设 </a><a href="http://chengdu.cdcxhl.cn/" target="_blank">成都网站设计 </a><a href="http://www.cdkjz.cn/" target="_blank">网站建设 </a><a href="http://www.36103.cn/baojia/" target="_blank">网站设计制作报价 </a><a href="http://www.cqcxhl.com/service/" target="_blank">品牌网站建设 </a><a href="https://www.cdcxhl.com/" target="_blank">网站建设公司 </a><a href="https://www.cdcxhl.com/" target="_blank">网站制作 </a><a href="http://chengdu.kswjz.com/" target="_blank">成都网站制作 </a><a href="http://chengdu.cdcxhl.com/" target="_blank">成都网站设计 </a><a href="http://seo.cdkjz.cn/wangzhan/" target="_blank">营销型网站建设 </a></div> </body> </html> <script src="/Public/Home/js/wow.min.js"></script> <script> if (!(/msie [6|7|8|9]/i.test(navigator.userAgent))) { new WOW().init(); }; </script> <div class="sidebar"> <ul> <li><a href="http://wpa.qq.com/msgrd?v=3&uin=244261566&site=www.bzwzjz.com&menu=yes" target="_blank"><img src="/Public/Home/images/right_qq.png" /></a></li> <li><a href="http://wpa.qq.com/msgrd?v=3&uin=1683211881&site=www.bzwzjz.com&menu=yes" target="_blank"><img src="/Public/Home/images/qq.png" /></a></li> <li class="tel"><a href="tel:028-86922220"><img src="/Public/Home/images/right_tel.png" /></a></li> <div class="wx"> <span class="weixin"><img src="/Public/Home/images/weixin.jpg"><br> 微信扫一扫在线咨询</span> </div> <li><a class="fx" href="#hero"><img src="/Public/Home/images/right_up.png" /></a></li> </ul> </div> <script type="text/javascript"> $(function () { $('.sidebar .fx').click(function () { $('html,body').animate({ scrollTop: '0px' }, 800); }); }); </script> <script type="text/javascript"> $(document).ready(function () { $("#fancybox-manual-b").click(function () { $.fancybox.open({ href: 'map.html', type: 'iframe', padding: 5 }); }) }); </script> <script> $(".con img").each(function(){ var src = $(this).attr("src"); //获取图片地址 var str=new RegExp("http"); var result=str.test(src); if(result==false){ var url = "https://www.cdcxhl.com"+src; //绝对路径 $(this).attr("src",url); } }); window.onload=function(){ document.oncontextmenu=function(){ return false; } } </script>