UpdatePanel的使用方法

news/2025/2/22 22:32:57
<div id="article_content" class="article_content clearfix"> <div id="content_views" class="htmledit_views"> 原文地址为: UpdatePanel的使用方法

<div class="htmledit_views"> UpdatePanel控件也是Ajax里用得最多的控件之一,UpdatePanel控件是用来局部更新网页上的内容,网页上要局部更新的内容必须放在UpdatePanel控件里,他必须和上一次说的ScriptManager控件一起使用。现在来看UpdatePanel的属性
<div style="line-height:200%;" align="left"> UpdatePanel 重要的属性如下: div>
<div style="line-height:200%;" align="center"> 属性 div> <div style="line-height:200%;" align="center"> 说明 div>
<div style="line-height:200%;"> ChildrenAsTriggers div> <div style="line-height:200%;"> 当UpdateMode属性为Conditional时,UpdatePanel中的子控件的异步回送是否会引发UpdatePanle的更新。 div>
<div style="line-height:200%;"> RenderMode div> <div style="line-height:200%;"> 表示UpdatePanel最终呈现的HTML元素。Block(默认)表示<div>,Inline表示<span> div>
<div style="line-height:200%;"> UpdateMode div> <div style="line-height:200%;"> 表示UpdatePanel的更新模式,有两个选项:Always和Conditional。Always是不管有没有Trigger,其他控件都将更新该UpdatePanel,Conditional表示只有当前UpdatePanel的Trigger,或ChildrenAsTriggers属性为true时当前UpdatePanel中控件引发的异步回送或者整页回送,或是服务器端调用Update()方法才会引发更新该UpdatePanel。 div>

<div style="line-height:200%;"> ChildrenAsTriggers:当UpdateMode属性为Conditional时,UpdatePanel中的子控件的异步回送是否会引发UpdatePanle的更新。 <div style="line-height:200%;"> RenderMode:表示UpdatePanel最终呈现的HTML元素。Block(默认)表示<div>,Inline表示<span> <div style="line-height:200%;"> UpdateMode:表示UpdatePanel的更新模式,有两个选项:Always和Conditional。Always是不管有没有Trigger,其他控件都将更新该UpdatePanel,Conditional表示只有当前UpdatePanel的Trigger,或ChildrenAsTriggers属性为true时当前UpdatePanel中控件引发的异步回送或者整页回送,或是服务器端调用Update()方法才会引发更新该UpdatePanel。
Contente Template:用来定义UpdatePanel的内容
Triggers:分别为AsyncPostBackTrigger和PostBackTrigger
AsyncPostBackTrigge用来指定某个服务器端控件以及其将触发的服务器端事件作为该UpdatePanel的异步更新触发器,它需要设置的属性有控件ID和服务端控件的事件;PostBackTrigger用来指定在UpdatePanel中的某个服务端控件,它所引发的回送不使用异步回送,而仍然是传统的整页回送
现在我们来做一个简单的实例:
div> <div style="border-right:#cccccc 1px solid;padding-right:5px;border-top:#cccccc 1px solid;padding-left:4px;font-size:13px;padding-bottom:4px;border-left:#cccccc 1px solid;padding-top:4px;border-bottom:#cccccc 1px solid;background-color:#eeeeee;"> <% @ Page Language = " C# "  AutoEventWireup = " true "  CodeFile = " Default.aspx.cs "  Inherits = " _Default "  %>

<! DOCTYPE html PUBLIC  " -//W3C//DTD XHTML 1.1//EN "  " http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd " >
< html xmlns = " http://www.w3.org/1999/xhtml " >
< head runat = " server " >
    
< title > Untitled Page </ title >
    
< style type = " text/css " >
         body 
{ background-attachment:fixed;
             
              
                background
-image:url(Blue hills.jpg);
                }

                
         .style1
         
{
                background
-position:top center;
         }

         
         
    
</ style >

</ head >
< body  onload = " oSpan.className='style1' "  >
    
< form id = " form1 "  runat = " server " >
    
< span style = " font-size:14; width:250; "  ID = " oSpan "
        onmouseover
= " this.className='style2' "  onmouseout = " this.className='style1' " ></ span >
        
< div >
            
< asp:ScriptManager ID = " ScriptManager1 "      runat = " server " >     
              
</ asp:ScriptManager >
        
</ div >
           
        
< asp:UpdatePanel ID = " uid "   runat = " server " >
        
            
< ContentTemplate >
            
                
< div  >
                    
< asp:Button ID = " Button1 "  runat = " server "  Text = " 异步回送 "  OnClick = " Button1_Click1 "  />& nbsp; & nbsp;
                    
< asp:Button ID = " Button2 "  runat = " server "  Text = " 整页回送 "  OnClick = " Button2_Click "  />< br  />
                    
< asp:GridView ID = " GridView1 "  runat = " server "  AutoGenerateColumns = " False "  Width = " 197px " >
                        
< Columns >
                            
< asp:BoundField DataField = " au_lname "  FooterText = " aaaa "  HeaderText = " au_lname "  />
                        
</ Columns >
                    
</ asp:GridView >
                    
< br  />
                   
< asp:Label ID = " Label1 "  runat = " server "  Text = " 当前时间 "  Font - Bold = " True "  Font - Size = " Large " ></ asp:Label >
                  
</ div >
            
</ ContentTemplate >
            
< Triggers >
                
< asp:AsyncPostBackTrigger    ControlID = " Button1 "  />
                
< asp:PostBackTrigger  ControlID = " Button2 "  />
            
</ Triggers >
              
        
</ asp:UpdatePanel >
          
< div id = " div1 "  >
              
& nbsp; </ div >
        
        
    
</ form >
</ body >
</ html >
div> div> <div style="line-height:200%;"> 表示UpdatePanel最终呈现的HTML元素。Block(默认)表示<div>,Inline表示<span> div> div> 里面包含了一个Triggers,里面第一个属性 AsyncPostBackTrigger指定Button1实现异步更新,而PostBackTrigger
指定Button2实现整页更新。
.CS代码为:
<div style="border-right:#cccccc 1px solid;padding-right:5px;border-top:#cccccc 1px solid;padding-left:4px;font-size:13px;padding-bottom:4px;border-left:#cccccc 1px solid;padding-top:4px;border-bottom:#cccccc 1px solid;background-color:#eeeeee;">   protected  void  Button1_Click1( object  sender, EventArgs e)
    
{
  
        SqlConnection conn 
= new SqlConnection("server=.;uid=sa;pwd=;database=pubs");
        
string sql1 = "select top 5 au_lname from authors ";
        SqlDataAdapter myAdapter 
= new SqlDataAdapter(sql1, conn);
        DataSet ds 
= new DataSet();
        myAdapter.Fill(ds, 
"bieminG");
        
//来自web service的dataset,这里随便一个ds就可以;
        this.GridView1.DataSource = ds.Tables["bieminG"].DefaultView; ;
        
this.GridView1.DataBind(); //数据绑定
    }
    
protected  void  Button2_Click( object  sender, EventArgs e)
    
{
        
this.Label1.Text = "11111";
    }
div>
Button1实现一个数据集的异步更新,BUTTON2就是一般的赋值了。看看是不是很简单呀!呵呵!  div>
转载请注明本文地址: UpdatePanel的使用方法
div> div> <div id="treeSkill">div>

http://www.niftyadmin.cn/n/1167415.html

相关文章

Android 6.x 新的运行时权限

android在不断发展&#xff0c;最近的更新 M 非常不同&#xff0c;一些主要的变化例如运行时权限将有颠覆性影响。惊讶的是android社区鲜有谈论这事儿&#xff0c;尽管这事很重要或许在不远的将来会引发很严重的问题。 这是今天我写这篇博客的原因。这里有一切关于android运行时…

HDU-2069-Coin Change

链接&#xff1a;https://vjudge.net/problem/HDU-2069 题意&#xff1a; 给你面值有1&#xff0c;5&#xff0c;10&#xff0c;25&#xff0c;50的币种&#xff0c;然后随意输入一个钱的数目&#xff0c;问用这些面值刚好凑成这个钱的方法有多少个&#xff08;最多100个硬币&a…

Android 中文 API (100) —— ScrollView

原文地址为&#xff1a; Android 中文 API (100) —— ScrollView前言 春节即至&#xff0c;谨代表Android中文翻译组全体同仁祝大家身体健康&#xff0c;工作顺利&#xff01;从第一篇译稿2010年8月27发布至今天2011年1月27整5个月&#xff0c;共发布100篇译文&#xff0c;3个…

力扣算法题—052N皇后问题2

跟前面的N皇后问题没区别&#xff0c;还更简单 1 #include "000库函数.h"2 3 //使用回溯法4 class Solution {5 public:6 int totalNQueens(int n) {7 int res 0;8 vector<int>x(n, -1);//标记9 NQueue(x, res, 0); 10 r…

Android应用瘦身,从18MB到12.5MB

开篇语 前阵子老大交给了我一个任务&#xff0c;主要是帮我们开发的直播应用做 Android 端的安装包瘦身&#xff0c;花了大概一周的时间把安装包从 18MB 减小到了 12.5MB。原本完全可以优化到 10MB 之下&#xff0c;但由于其他原因的限制&#xff0c;所以目前阶段只到 12.5MB …

Mysql Innodb 引擎优化 参数(innodb_buffer_pool_size)

原文地址为&#xff1a; Mysql Innodb 引擎优化 参数&#xff08;innodb_buffer_pool_size&#xff09;在mysql的学习过程中&#xff0c;要是不把一些基本概率弄的很清楚&#xff0c;难免显得过于不专业。 作用&#xff1a; 这个参数主要作用是缓存innodb表的索引&#xff0c;数…

Java原子类操作原理剖析

◆ CAS的概念 ◆ 对于并发控制来说&#xff0c;使用锁是一种悲观的策略。它总是假设每次请求都会产生冲突&#xff0c;如果多个线程请求同一个资源&#xff0c;则使用锁宁可牺牲性能也要保证线程安全。而无锁则是比较乐观的看待这个问题&#xff0c;它会假设每次访问都没有冲突…

android高级工程师应该会的知识

图片来自网上&#xff0c;侵删&#xff1a; 版权声明&#xff1a;本文为博主原创文章&#xff0c;转载时请著名出处&#xff1a;http://blog.csdn.net/dg_summer