tubachkhoa2004
23-12-2009, 21:06
AJAX đang ngày càng trở nên phổ biến và bạn muốn sử dụng công nghệ này. Đây là một giải pháp có thể nói là đảm bảo bạn sẽ vô cùng hài lòng vì 3 tính cơ bản:
- Dễ dàng sử dụng bằng ngôn ngữ hướng tự nhiên, hướng truy vấn
- Bảo mật cao vì có kiểm tra quyền hạn và tạo sessionID cho mỗi lời gọi AJAX, chống ddos
- Tốc độ tối ưu vì sử dụng cơ chế tạo động một class lúc runtime và delegate method vào class này, nên tốc độ tương đương gọi hàm trực tiếp, thậm chí với vòng for nhiều có thể nhanh hơn.
Ví dụ tích hợp bộ thư viện nổi tiếng DHTMLX Suite :
http://tubachkhoa2004.t35.com/dhtmlxgrid.PNG
Mã file aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
$(function() {
mygrid = new dhtmlXGridObject('gridbox');
mygrid.setImagePath(toAbsolutePath("~/Content/Scripts/dhtmlx/codebase/imgs/"));
mygrid.setSkin("dhx_skyblue");
mygrid.parse($.callback('GetFormat'));
mygrid.parse($.callback('GetData'), 'json');
});
</script>
</head>
<body>
<div id="gridbox" style="background-color:white;width:500px;height:250px;overflow:hidd en"></div>
</body>
</html>
Mã file C#:
public partial class _Default : CallBackPage
{
CMSDataContext db = DataContextManager<CMSDataContext>.GetInstance();
protected void Page_Load(object sender, EventArgs e)
{
Register.DHTMLXGrid(this);
Register.JQueryToAbsoluteFunction(this);
}
public string GetFormat()
{
return String.Format(@"<rows><head>
<column width='50' type='ro' align='center' sort='str'>Phiên bản</column>
<column width='*' type='co' align='left' sort='str'>Vùng{0}</column>
</head></rows>", db.Zones.Select(c =>String.Format(@"<option value=""{0}"">{1}</option>", c.ZoneID, c.Title)).Join());
}
public object GetData()
{
return new {
rows = db.Distributions.Select(c => new { id = c.ContentID, data = new object[] {c.Version,c.ZoneID}})
};
}
}
- Dễ dàng sử dụng bằng ngôn ngữ hướng tự nhiên, hướng truy vấn
- Bảo mật cao vì có kiểm tra quyền hạn và tạo sessionID cho mỗi lời gọi AJAX, chống ddos
- Tốc độ tối ưu vì sử dụng cơ chế tạo động một class lúc runtime và delegate method vào class này, nên tốc độ tương đương gọi hàm trực tiếp, thậm chí với vòng for nhiều có thể nhanh hơn.
Ví dụ tích hợp bộ thư viện nổi tiếng DHTMLX Suite :
http://tubachkhoa2004.t35.com/dhtmlxgrid.PNG
Mã file aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
$(function() {
mygrid = new dhtmlXGridObject('gridbox');
mygrid.setImagePath(toAbsolutePath("~/Content/Scripts/dhtmlx/codebase/imgs/"));
mygrid.setSkin("dhx_skyblue");
mygrid.parse($.callback('GetFormat'));
mygrid.parse($.callback('GetData'), 'json');
});
</script>
</head>
<body>
<div id="gridbox" style="background-color:white;width:500px;height:250px;overflow:hidd en"></div>
</body>
</html>
Mã file C#:
public partial class _Default : CallBackPage
{
CMSDataContext db = DataContextManager<CMSDataContext>.GetInstance();
protected void Page_Load(object sender, EventArgs e)
{
Register.DHTMLXGrid(this);
Register.JQueryToAbsoluteFunction(this);
}
public string GetFormat()
{
return String.Format(@"<rows><head>
<column width='50' type='ro' align='center' sort='str'>Phiên bản</column>
<column width='*' type='co' align='left' sort='str'>Vùng{0}</column>
</head></rows>", db.Zones.Select(c =>String.Format(@"<option value=""{0}"">{1}</option>", c.ZoneID, c.Title)).Join());
}
public object GetData()
{
return new {
rows = db.Distributions.Select(c => new { id = c.ContentID, data = new object[] {c.Version,c.ZoneID}})
};
}
}