通常我们看到局部刷新就会想到Ajax,但是我今天要说的是c#的一个控件,只要把服务器按钮和要刷新的区域放在该控件内就能实现局部刷新。

当然它必须和ScriptManager控件一起使用。

UpdatePanel重要的属性如下:
属性
说明
ChildrenAsTriggers
当UpdateMode属性为Conditional时,UpdatePanel中的子控件的异步回送是否会引发UpdatePanle的更新。
RenderMode
表示UpdatePanel最终呈现的HTML元素。Block(默认)表示<div>,Inline表示<span>
UpdateMode
表示UpdatePanel的更新模式,有两个选项:Always和Conditional。Always是不管有没有Trigger,其他控件都将更新该UpdatePanel,Conditional表示只有当前UpdatePanel的Trigger,或ChildrenAsTriggers属性为true时当前UpdatePanel中控件引发的异步回送或者整页回送,或是服务器端调用Update()方法才会引发更新该UpdatePanel。

下面我们来个小实例:

前端代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="WebApplication2.WebForm4" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>UpdatePanel局部刷新</title>
<script src="http://apps.bdimg.com/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
//document.getElementById("Button2").click(fun);
function fun() {
document.getElementById("Button2").setAttribute("checked", "checked");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server" >
<ContentTemplate>
<fieldset>
<legend>UpdatePanel content</legend>
<!-- Other content in the panel. -->
<input type="checkbox" checked="checked" />
<input id="ch" type="checkbox" />
<input type="checkbox" checked="checked" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="ccc" OnClientClick="return fun()" />
<iframe id="iframesun" runat="server" style="width:100%;height:944px"></iframe>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

 后端代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; namespace WebApplication2
{
public partial class WebForm4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void ccc(object sender, EventArgs e) {
this.TextBox1.Text= "你好UpdatePanel";
this.iframesun.Attributes.Add("src", "https://www.baidu.com/");
}
}
}

 这样我们实现了,不刷新整个页面,得到TextBox1赋值,和加载了一个百度的iframe。

c#用UpdatePanel实现接局部刷新的更多相关文章

  1. ASP.Net UpdatePanel控件 局部刷新 && 弹出提示信息

    参考博客: https://blog.csdn.net/qq_35019337/article/details/69972552 https://blog.csdn.net/huangyezi/art ...

  2. Webform——页面局部刷新

    有一些数据控件,每次更改它的值后,都会重新查询数据库,然后再重新显示出来. 这样每次都会刷新全部页面,如果是一些信息量很庞大的页面,就会出现卡顿的现象,为了避免这种情况,就用到了局部刷新. 所用到的控 ...

  3. updatepanel用法之triggers(局部刷新,全部刷新)使用示例

    asyncpostbacktrigger(异步回调触发器):局部刷新,只刷新updatepanel内部的内容postbacktrigger(普通回调触发器):全部刷新 <asp:ScriptMa ...

  4. ScriptManager和UpdatePanel控件实现局部刷新

    ScriptManager和UpdatePanel控件联合使用可以实现页面异步局部更新的效果.其中的UpdatePanel就是设置页面中异步局部更新区域,它必须依赖于ScriptManager存在,因 ...

  5. updatepanel局部刷新功能,实现注册时对用户名的检测

    updatepanel的使用 通过将控件放入到updatepanel中,实现局部刷新. 前台代码:<asp:ScriptManager ID="ScriptManager1" ...

  6. asp.net UpdatePanel 不能局部刷新问题汇总

    1.web.config 配置问题.   关于web.config的配置方面网上有很多资料参考,按照其方法做即可实现. 2.网站 Framework 版本变化造成不能局部刷新问题    版本更新时,会 ...

  7. C#服务控件UpdatePanel的局部刷新与属性AutoPostBack回传

    C#服务控件许多都有AutoPostBack这一属性(AutoPostBack意思是自动回传,也就是说此控件值更改后是否和服务器进行交互),如下代码所示: protected void Textbox ...

  8. ASP.NET实现省市区三级联动(局部刷新)

    跟前一篇ASP.NET实现年月日三级联动(局部刷新)一样,没什么技术含量,直接上代码 <asp:ScriptManager ID="ScriptManager1" runat ...

  9. ASP.Net用jQuery ajax实现页面局部刷新

    刚开始的时候使用asp的updatepanel控件实现局部刷新,而且在本地运行正确,但是部署到服务器上就变成整个页面全部刷新了.服务器用的是Windows server2000,本地机子上用的是win ...

随机推荐

  1. PHP调试小错误汇总

    1.中文显示乱码 解决:加上header('Content-type:text'); 2.Unable to find the wrapper "https 解决:到php.ini中把ext ...

  2. extjs3EmptyText 上传自动清空的问题

    在extjs3表单的操作中,输入框经常有提示性的默认字段,比如: // === 接入单位的Form表单 ====== var jrdwForm = new Ext.form.FormPanel({ b ...

  3. js 动态创建标记

    innerHTML:一旦使用了这个属性,它的全部内容都要被替换掉.且不会返回任何对刚插入的内容的引用 与document.write()方法一样,innerHTML属性也是HTML专有属性,不能用于任 ...

  4. HTML中行内元素和块级元素的区别及转换

    区别可以去找 “html文档流”相关的资料去学习,最主要的区别就是元素是占据一行还是挤在一行 转换的方式是用css的display属性 display:block; /*转换为块级*/display: ...

  5. forEach、for...in、for...of

    forEach 数组实例的遍历方法 const arr=['red', 'green', 'blue']; arr.forEach(function(element, index) { console ...

  6. docker swarm使用keepalived+haproxy搭建基于percona-xtradb-cluster方案的高可用mysql集群

    一.部署环境 序号 hostname ip 备注 1 manager107 10.0.3.107 centos7;3.10.0-957.1.3.el7.x86_64 2 worker68 10.0.3 ...

  7. spring cloud 学习之服务消费者(rest+ribbon)

    学习自 http://blog.csdn.net/forezp/article/details/81040946 方志朋的博客 在微服务架构中,业务都会被拆分成一个独立的服务,服务与服务的通讯是基于h ...

  8. selenium webdriver 移动到某个位置,滚动到某个位置

    https://blog.csdn.net/xiaosongbk/article/details/70231564

  9. (二)、Python 基础

    Python入门 一.第一句Python 在 /home/dev/ 目录下创建 hello.py 文件,内容如下: print "hello,world" 执行 hello.py ...

  10. 30-RoutingMiddleware介绍以及MVC引入

    1-构建路由 public class Startup { // This method gets called by the runtime. Use this method to add serv ...