我已经实现了一个asp.net日历,以便能够选择日期并将其保存在数据库中。但是,每次按下它都会刷新整个页面。 例如,如果我按下日期刷新,如果我按箭头移动到下个月,该页面也会刷新。
如何阻止用户在每次更改时刷新它?
以下是代码:
HTML:
<tr>
<td>Start Date :</td>
</tr>
<tr>
<td><asp:Calendar ID="StartDate" runat="server"></asp:Calendar></td>
</tr>
<tr>
<td>End Date :</td>
</tr>
<tr>
<td><asp:Calendar ID="EndDate" runat="server"></asp:Calendar></td>
</tr>
C#:
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class admin_EventsUpdate : System.Web.UI.Page
{
int EventId = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["AdminSession"] == null)
Response.Redirect("~/admin/index.aspx");
EventId = Convert.ToInt32(Request["EventId"].ToString());
if (!IsPostBack && EventId != 0)
{
Submit.Text = "Update";
DataSet ds = Admin.GetEvent(EventId);
foreach (DataRow row in ds.Tables[0].Rows)
{
if (row["startdate"].ToString() !="" )
{
StartDate.SelectedDate = Convert.ToDateTime(row["startdate"].ToString());
StartDate.VisibleDate = StartDate.SelectedDate;
}
if (row["enddate"].ToString() != "")
{
EndDate.SelectedDate = Convert.ToDateTime(row["enddate"].ToString());
EndDate.VisibleDate = EndDate.SelectedDate;
}
}
}
}
protected void Update_Click(object sender, EventArgs e)
{
string SD;
string ED;
if (StartDate.SelectedDate.Date == DateTime.MinValue.Date)
SD = "";
else
{
DateTime sdt = StartDate.SelectedDate;
SD = sdt.Date.Year + "-" + sdt.Date.Month + "-" + sdt.Date.Day;
}
if (EndDate.SelectedDate.Date == DateTime.MinValue.Date)
ED = "";
else
{
DateTime sdt = EndDate.SelectedDate;
ED = sdt.Date.Year + "-" + sdt.Date.Month + "-" + sdt.Date.Day;
}
if (EventId != 0)
Admin.UpdateEvent(SD, ED);
else
Admin.AddEvent(SD, ED);
Response.Redirect("~/admin/Events.aspx");
}
}