通过JavaScript更新UpdatePanel备忘

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>">
3<html xmlns="<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>">
4<head runat="server">
5  <title>无标题页</title>
6</head>
7<body>
8  <form id="form1" runat="server">
9  <div >
10  <asp:ScriptManager ID="ScriptManager1" runat="server">
11  
12  </asp:ScriptManager>
13  <script language ="javascript">
14  function ComfirmRefresh()
15  {
16    if(confirm("你确认要刷新吗?"))
17    {
18    //第一个参数是你希望提交到服务器的控件的ID号,第二个参数是事件参数
19    __doPostBack("UpdatePanel1","Refresh");
20    }
21  }
22  </script>
23  <input id="Button1" type="button" value="button" onclick="ComfirmRefresh()" />
24  <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode ="Conditional">
25    <ContentTemplate>
26      <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
27    </ContentTemplate>
28  </asp:UpdatePanel>
29  </div>
30  </form>
31</body>
32</html>
1public partial class _Default : System.Web.UI.Page
2{
3  protected void Page_Load(object sender, EventArgs e)
4  { //当前ScriptManager1回发的值是AsyncPostback并且导致ScriptManager1的异步回发事件的控件为UpdatePanel1时。
5    if (ScriptManager1.IsInAsyncPostBack && ScriptManager1.AsyncPostBackSourceElementID == "UpdatePanel1")
6      //label1获取系统当前时间。
7      Label1.Text = DateTime.Now.ToString();

 

posted on   空明流光  阅读(210)  评论(0编辑  收藏  举报

编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示