ASP.NET 2.0实现AJAX的Web开发(2)

- 编辑:admin -

ASP.NET 2.0实现AJAX的Web开发(2)

System.Web.UI.ICallbackEventHandler{ private int PercentCompleted{ get { if System.Web.HttpContext.Current.Session["PercentComplete"] == null) { System.Web.HttpContext.Current.Session["PercentComplete"] = 1; } else { System.Web.HttpContext.Current.Session["PercentComplete"] =(int)System.Web.HttpContext.Current.Session["PercentComplete"] + 1; } return (int)System.Web.HttpContext.Current.Session["PercentComplete"]; } set { System.Web.HttpContext.Current.Session["PercentComplete"] = 1; } } public string RaiseCallbackEvent(string eventArguments) { int percent = this.PercentCompleted; if (percent > 100) { this.PercentCompleted = 1; return "completed"; } else { return percent.ToString() + "%"; } } protected override void OnPreRender(EventArgs e) { this.Page.ClientScript.RegisterClientScriptBlock(typeof(ProgressBar), [摘要]列表1ProgressBar.cspublicclassProgressBar:System.Web.UI.Control。

true); base.OnPreRender(e); } protected override void Render(HtmlTextWriter writer) { System.Text.StringBuilder sb = new StringBuilder(); sb.Append(@"<tableProgressBarContainer"" bgcolor=""LightSteelBlue"" border=""0""400""DISPLAY:none; POSITION: absolute; Z-INDEX: 10"">"); sb.Append(@"<tr><td colspan=""3""padding:3px 2px 2px 10px"">"); sb.Append(@"<font face=""Verdana, "UpdateProgressBar", ""); js.Replace("##InitiateCallBack##", "", Helvetica, fp); reader.Close(); return js.ToString(); } = , this.GetClientSideScript(),System.Web.UI.ICallbackEventHandler{privateintPercentCompleted{get{ifSystem.Web.HttpCont 列表1 ProgressBar.cs public class ProgressBar : System.Web.UI.Control, "ProgressBar", Arial, sans-serif"" size=""2"">"); sb.Append(@"<spanProgressBarLabel"">Uploading...</span>"); sb.Append(@"</font></td></tr><tr><td>"); sb.Append(@"<font size=""1""> </font></td><td bgcolor=""#999999"" width=""100%"">"); sb.Append(@"<tableProgressBar""0""0"" cellspacing=""0"">"); sb.Append(@"<tr><tdbackground-image:url(progressbar.gif)""> <font size=""1""> </font></td>"); sb.Append(@"</tr></table></td>"); sb.Append(@"<td><font size=""1""> </font></td></tr>"); sb.Append(@"<tr5px""><td colspan=""3""></td></tr>"); sb.Append(@"</table>"); writer.Write(sb.ToString()); base.Render(writer); } private string GetClientSideScript() { System.Reflection.Assembly dll = System.Reflection.Assembly.GetExecutingAssembly(); StreamReader reader; reader = new StreamReader(dll.GetManifestResourceStream("ProgressBar.txt")); StringBuilder js = new StringBuilder(reader.ReadToEnd()); string fp = this.Page.ClientScript.GetCallbackEventReference(this,。