Easyui登陆页面制作
一、登陆页面HTML
<%@ Page Language="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inherits="Webapplication1.EasyUITest.WebForm1"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>Login</title><scriptsrc="../Scripts/jquery-1.6.min.js"type="text/javascript"></script><scriptsrc="../Scripts/jquery.easyui.min.js"type="text/Javascript"></script><linkhref="../Scripts/themes/icon.CSS"rel="stylesheet"type="text/css"/><linkhref="../Scripts/themes/default/easyui.css"rel="stylesheet"type="text/css"/><scripttype="text/javascript">$(function() {
$("#win").window({
title:"Login",
width:300,
height:200,
collapsible:false,
minimizable:false,
maximizable:false,
closable:false,
closed:false,
draggable:false,
resizable:false,
modal:true});
});functionlogin() {varname=$("#txt_name").val();varPSD=$("#txt_psd").val();
$.Ajax({
type:"POST",
dataType:"json",
url:"Service/login.ashx",
data: { Method:"Login"},
success:function(data) {
$.messager.alert("消息", data,"info");
},
error:function() {
$.messager.alert("消息","错误!","info");
}
});
}</script></head><body><formid="form1"runat="server"><divid="win"class="easyui-window"><table><tr><td>Name:</td><td><inputid="txt_name"type="text"/></td></tr><tr><td>PassWord:</td><td><inputid="txt_psd"type="text"/></td></tr><tr><td><ahref="#"class="easyui-linkbutton"iconcls="icon-ok"onclick="login()">Login</a></td><td><ahref="#"class="easyui-linkbutton"iconcls="icon-cancel">Cancel</a></td></tr></table></div></form></body></html>
二、一般处理程序
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Reflection;usingSystem.Web.sessionState;usingNewtonsoft.Json;namespaceWebApplication1.EasyUITest.Service
{///<summary>///login 的摘要说明///</summary>publicclasslogin : IHttpHandler, IRequiresSessionState
{
HttPRequest Request;
HttpResponse Response;
HttpSessionState Session;
HttpServerUtility Server;//HttpCookie Cookie;publicvoidProcessRequest(HttpContext context)
{//不让浏览器缓存context.Response.Buffer =true;
context.Response.ExpiresAbsolute= DateTime.Now.AddDays(-1);
context.Response.AddHeader("pragma","no-cache");
context.Response.AddHeader("cache-control","");
context.Response.CacheControl="no-cache";
context.Response.ContentType="text/plain";
Request=context.Request;
Response=context.Response;
Session=context.Session;
Server=context.Server;stringmethod = Request["Method"].ToString();
MethodInfo methodInfo=this.GetType().GetMethod(method);
methodInfo.Invoke(this,null);
}publicvoidLogin()
{
Response.Write(JsonConvert.SerializeObject(DateTime.Now.ToString()));
}
[Serializable]publicclassInfomation
{publicstringid {get;set; }publicstringmsg {get;set; }
}publicboolIsReusable
{get{returnfalse;
}
}
}
}
三、Index页面
<%@ Page Language="C#"AutoEventWireup="true"CodeBehind="index.aspx.cs"Inherits="WebApplication1.EasyUITest.index"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title></title><scriptsrc="../Scripts/jquery-1.6.2.min.js"type="text/javascript"></script><scriptsrc="../Scripts/jquery.easyui.min.js"type="text/javascript"></script><linkhref="../Scripts/themes/default/easyui.css"rel="stylesheet"type="text/css"/><linkhref="../Scripts/themes/icon.css"rel="stylesheet"type="text/css"/><scripttype="text/javascript">$(function() {
$("#tt").tree({
checkbox:false,
url:"Service/index.ashx?Method=GetTreeData&id=0",
onBeforeExpand:function(node, param) {
$(this).tree("options").url="Service/index.ashx?Method=GetTreeData&id="+node.id;
},
onClick:function(node) {
$("#contentPage").attr("src", node.attributes);
}
});
});functionOpen() {
$("#contentPage").attr("src","WebForm1.aspx");
}</script></head><bodyclass="easyui-layout"><divregion="north"style="height: 100px;"></div><divregion="west"style="width: 200px;"title="west"split="true"><ulid="tt"></ul></div><divid="divCenter"region="center"title="center"style="padding: 5px; background: #eee;"><iframeid="contentPage"width="100%"height="100%"frameborder="0"marginheight="0"marginwidth="0"></iframe></div></body></html>
四、Index一般处理程序
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.SessionState;usingSystem.Reflection;usingSystem.Data.SqlClient;usingSystem.Configuration;usingSystem.Data;usingSystem.Text;namespaceWebApplication1.EasyUITest.Service
{///<summary>///index 的摘要说明///</summary>publicclassindex : IHttpHandler
{
HttpRequest Request;
HttpResponse Response;
HttpServerUtility Server;
HttpSessionState Session;publicreadonlystringconnectionString = ConfigurationManager.ConnectionStrings["BookConnectionString"].ToString();publicvoidProcessRequest(HttpContext context)
{
context.Response.Buffer=true;
context.Response.ExpiresAbsolute= DateTime.Now.AddDays(-1);
context.Response.AddHeader("pragma","no-cache");
context.Response.AddHeader("cache-control","");
context.Response.CacheControl="no-cache";
context.Response.ContentType="text/plain";
Request=context.Request;
Response=context.Response;
Session=context.Session;
Server=context.Server;stringmethod = Request["Method"].ToString();
MethodInfo methodInfo=this.GetType().GetMethod(method);
methodInfo.Invoke(this,null);
}publicvoidGetTreeData()
{stringid = Request.QueryString["id"].ToString();stringsqlStr ="SELECT * FROM dbo.tree where parentid="+id;
DataSet ds=newDataSet();using(SqlConnection conn =newSqlConnection(connectionString))
{using(SqlDataAdapter da =newSqlDataAdapter(sqlStr, conn))
{
da.Fill(ds);
}
}
StringBuilder sb=newStringBuilder();
sb.Append("[");foreach(DataRow rinds.Tables[0].Rows)
{
sb.Append("{");
sb.AppendFormat("\"id\": \"{0}\", \"text\": \"{1}\", \"state\": \"closed\",\"attributes\":\"{2}\"", r["id"], r["name"], r["url"]);
sb.Append("},");
}
sb= sb.Remove(sb.Length -1,1);
sb.Append("]");
Response.Write(sb.ToString());
}publicboolIsReusable
{get{returnfalse;
}
}
}
}