📄 default.aspx.cs
字号:
// *******************************************************************************************
//
// Ajax.NET Professional - The free AJAX implementation for the Microsoft.NET Framework
//
// Copyright (C) 2005 Michael Schwarz, info@schwarz-interactive.de
//
// *******************************************************************************************
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace AjaxProSample
{
[AjaxPro.AjaxClass("WebForm1")] // remove this if you want to use the complete Namespace
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
AjaxPro.Utility.RegisterEnumForAjax(typeof(AjaxProSample.NamespaceTest.Demo.GenderType));
AjaxPro.Utility.RegisterTypeForAjax(typeof(WebForm1));
AjaxPro.Utility.RegisterTypeForAjax(typeof(WebForm1));
AjaxPro.Utility.RegisterTypeForAjax(typeof(AjaxProSample.NamespaceTest.Demo.DemoMethods));
}
#region Ajax.NET methods
[AjaxPro.AjaxMethod]
public void Test1(string s)
{
System.Web.HttpContext.Current.Application["ss"] = s;
}
[AjaxPro.AjaxMethod]
public string Test2()
{
return System.Web.HttpContext.Current.Application["ss"].ToString();
}
[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
public string SayHello(string s)
{
if(System.Web.HttpContext.Current.Session["hello"] != null)
return "SessionState: " + System.Web.HttpContext.Current.Session["hello"].ToString();
System.Web.HttpContext.Current.Session["hello"] = "Hello " + s;
return "Hello " + s;
}
[AjaxPro.AjaxMethod]
public DateTime[] Sleep(DateTime start, int seconds)
{
DateTime[] r = new DateTime[2];
System.Threading.Thread.Sleep(seconds * 1000);
r[0] = start;
r[1] = DateTime.Now;
return r;
}
[AjaxPro.AjaxMethod(10)]
public DataSet GetSqlServerInfo()
{
string connStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connStr);
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("SELECT GETDATE() AS MyTime", conn);
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd);
DataSet ds = new DataSet();
conn.Open();
da.Fill(ds);
conn.Close();
conn.Dispose();
return ds;
}
[AjaxPro.AjaxMethod]
public string GetDataSetXml(DataSet ds)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
ds.WriteXml(ms);
ms.Position = 0;
System.IO.StreamReader sr = new System.IO.StreamReader(ms);
string s = sr.ReadToEnd();
sr.Close();
return s;
}
#endregion
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -