The AJAX extensions in ASP. Scriptmanage and UpdatePanel can be used together to achieve local refresh, improve speed and save network traffic
Front Code:
<! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 transitional//en""Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">"Http://www.w3.org/1999/xhtml">"Server"> <title></title> "Form1"Runat="Server"> <div> <asp:scriptmanager id="ScriptManager1"Runat="Server"/> <asp:updatepanel id="UpdatePanel1"Runat="Server"> <ContentTemplate> <asp:textbox id="TextBox1"Runat="Server"Ontextchanged="Change"autopostback="True"></asp:TextBox> <asp:label id="Label1"Runat="Server"Text="Label"></asp:Label> <asp:button id="Button1"Runat="Server"Onclick="Button1_Click"Text="Button"/> <asp:timer id="Timer1"Runat="Server"Enabled="False "Interval=" 1000 " Ontick= timer1_ Tick "> </asp:Timer> <asp:button id=" button2 "Runat=" Server "Onclick=" Button2_click "Text=" Button
Background code:
Namespaceajaxtest{PublicPartialClassScriptManageAjax:System.Web.UI.Page {Protectedvoid Page_Load (Objectsender, EventArgs e) {//Scriptmanager.registerstartupscript (this. UpdatePanel1, this. GetType (), "Updatescript", "alert (' Sorry, account and password error ')", true);}Protectedvoid Button1_Click (Objectsender, EventArgs e) {String str =String. Format ("The currently selected value is: {0}, Time is: {1}",This. DropDownList1.SelectedItem.Text, DateTime.Now.ToString ());this. Label1.Text = Str;} protected void button2_click ( object sender, EventArgs e) { string str = string. Format ( " The currently selected value is: {0}, Time is: {1} thisthis. Label1.Text = str; Response.Write ( "xx" Span style= "color: #000000;" >); } }}
Description: You need to implement the content of the local refresh, written in the UpdatePanel1 tag.
Attention:
We used to use Response.Write () when using ASP.
Use ScriptManager to realize JS registration can.
code example: Scriptmanager.registerstartupscript (this. UpdatePanel1, this. GetType (), "Updatescript", "alert (' Sorry, account and password error ')", true);
The practice of this feature
First introduced the function: 1. You can click on the button to enter the editing page to edit the function, set 2. The page can be a realistic day of work content
Foreground aspx page
<%@ page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>
<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:scriptmanager id= "ScriptManager1" runat= "Server" >
</asp:ScriptManager>
<asp:updatepanel id= "UpdatePanel1" runat= "server" updatemode= "Always" >
<ContentTemplate>
<div style= "width:100%" align= "Center" >
<asp:calendar id= "Calschedule" runat= "Server" font-size= "X-small" ondayrender= "Calschedule_dayrender" Borderstyle= "None" showgridlines= "True" prevmonthtext= " last month" NextMonthText= " Next month "daynameformat=" full "bordercolor=" #999999 "backcolor=" Transparent " height= "92%" width= "100%" onselectionchanged= "calschedule_selectionchanged" >
<todaydaystyle backcolor= "Transparent" borderstyle= "Solid" borderwidth= "2px" bordercolor= "Cornflowerblue" > </TodayDayStyle>
<daystyle horizontalalign= "left" font-bold= "True" verticalalign= "Top" ></DayStyle>
<weekenddaystyle backcolor= "White" forecolor= "Red" bordercolor= "white" ></WeekendDayStyle>
<nextprevstyle forecolor= "#223999" cssclass= "TD" ></NextPrevStyle>
<dayheaderstyle backcolor= "#BFE6F9" height= "10px" font-size= "Smaller" ></DayHeaderStyle>
<titlestyle backcolor= "#66CCFF" height= "10px" cssclass= "Headcenter" ></TitleStyle>
</asp:Calendar>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
CS Page
Using MYOFFICE.BLL;
Using Myoffice.models;
Using Myoffice.utils;
Using System;
Using System.Collections.Generic;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.HtmlControls;
Using System.Web.UI.WebControls;
public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{
}
protected void Calschedule_dayrender (object sender, Dayrendereventargs e)
{
MyOffice.Models.User User = (MyOffice.Models.User) session["Login"];
customizing display content
CalendarDay calday = E.day;
Gets the cell that represents the rendered space
TableCell TC = E.cell;
Cndate dt = chinadate.getchinadate (calday.date);//Lunar Conversion object
if (calday.isothermonth)
{
Tc. Controls.clear ();
}
Else
{
Try
{
HyperLink ahyperlink = new HyperLink ();
Ahyperlink.imageurl = "~/images/add_schedule.gif";
Ahyperlink.tooltip = "new Personal schedule";
Ahyperlink.navigateurl = "aaa.aspx?userid=" + user. UserId + "&today=" + calDay.Date.ToShortDateString ();//get to people, etc.
Tc. Controls.Add (New LiteralControl (" " + " " + " "));
Tc. Controls.Add (Ahyperlink);
Tc. Controls.Add (New LiteralControl ("<br>" + Dt.cnstrmonth + "month" + dt.cnstrday);//Add Lunar date
Tc. Controls.Add (New LiteralControl ("<br>" + dt.cnsolarterm);//Add Lunar solar terms
Tc. Controls.Add (New LiteralControl ("<br>" + Dt.cnftvs);//Add Day
Ilist<schedule> schedules = Schedulemanager.searchschedule (CalDay.Date.ToShortDateString (),-1, user. UserName, false);
if (schedules! = NULL)
{
string str = NULL;
foreach (Schedule Schedule in schedules)
{
HtmlAnchor ha = new HtmlAnchor ();
ha. HRef = "bbb.aspx?userid=" + user. UserId + "&scheduleid=" + schedule. ScheduleID + "&today=" + calDay.Date.ToShortDateString ();
Try
{
str = schedule. Title.substring (0, 3);
}
Catch
{
str = schedule. Title.tostring ();
}
Ha. InnerText = "@" + schedule. BeginTime.Hour.ToString () + ":" + schedule. BeginTime.Minute.ToString () + str + "...";
Tc. Controls.Add (New LiteralControl (" " + " " + " "));
Tc. Controls.Add (New LiteralControl ("<br>"));
Tc. Controls.Add (HA);
}
}
}
catch (Exception ex)
{
Response.Write (ex. ToString ());
}
e.cell.attributes["onmouseover"] = "javascript:this.style.backgroundcolor= ' #fff7ce '; cursor= ' hand ';";
e.cell.attributes["onmouseout"] = "javascript:this.style.backgroundcolor= ' #ffffff '";
}
}
}
. NET Controls