asp.net Ajax刷新和无刷新的区别

时间:2022-09-13 16:03:38

asp.net Ajax刷新和无刷新的区别

无刷新按钮btnShua

刷新按钮btnWu

label控件和calendar控件在updatePanel中显示

两个button按钮在div中

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

 <!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></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
<br />
<br />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnShua" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<div> <asp:Button ID="btnShua" runat="server" Height="21px" OnClick="btnShua_Click" Text="选择日期(刷新)" Width="162px" />
<asp:Button ID="btnWu" runat="server" OnClick="btnShua_Click" Text="选择日期(无刷新)" /> </div>
</form>
</body>
</html>

因为第一个按钮是无刷新的  应该也在updatePanel中显示,所以更改如下属性,单击updatepanel

asp.net Ajax刷新和无刷新的区别

asp.net Ajax刷新和无刷新的区别

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text; public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void btnShua_Click(object sender, EventArgs e)
{
string[] week = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
StringBuilder sbDate = new StringBuilder();
sbDate.Append("请选择日期是:");
sbDate.Append(Calendar1.SelectedDate.Year + "年");
sbDate.Append(Calendar1.SelectedDate.Month + "月");
sbDate.Append(Calendar1.SelectedDate.Day + "日");
sbDate.Append(week[(int)Calendar1.SelectedDate.DayOfWeek]);
Label1.Text = sbDate.ToString(); }
}

然后两个按钮的单击事件都改成 btnShua_click

asp.net Ajax刷新和无刷新的区别