一、登录的实现 *Forms身份认证*A)web.config <!-- Default.aspx 是登录页面--> <authentication mode="Forms"> <forms name=".ASPXUSERDEMO" loginUrl="Default.aspx" protection="All" timeout="60" /> </authentication> <!--configuration上增加节点,排除不需要导航到登录页面的页面。--> <location path="default.aspx"> <system.web> <authorization> <allow users="*" /> </authorization> </system.web> </location>B)用户名和密码验证成功后增加 System.Web.Security.FormsAuthentication.RedirectFromLoginPage(用户名,false); Response.Redirect("Main.aspx",true); //main.aspx是主窗口页面C)获得用户标识 string userid=System.Web.HttpContext.Current.User.Identity.Name;D)登出 System.Web.Security.FormsAuthentication.SignOut(); //登出二、IEWebControl的用法 *Toolbar客户端事件*A)在工程中包含IEWebControl中的htc(如:toolbar.htc)B)aspx页面 <HTML XMLNS:td> <head> <?IMPORT NAMESPACE="tb" IMPLEMENTATION="htc/toolbar.htc"/> <script language="javascript"> function toolbar_click() { var oButton = window.event.srcNode; var iButton = oButton.getAttribute("id"); switch(iButton) { case 'add': f_add(); break; case 'modify': f_modify(); break; case 'delete': f_delete(); break; case 'refresh': f_refresh(); break; } } </script> </head> <body topMargin="0" MS_POSITIONING="GridLayout"> <tb:TOOLBAR onbuttοnclick="toolbar_click()"> <!-- MOVEMENT="move-dock" --> <tb:TOOLBARGRIPPER/> <tb:TOOLBARBUTTON IMAGEURL="htc/images/root.gif" id="add" TEXT="新增"/> <tb:TOOLBARBUTTON id="modify" TEXT="修改"/> <tb:TOOLBARBUTTON id="delete" TEXT="删除"/> <tb:TOOLBARSEPARATOR/> <tb:TOOLBARBUTTON id="refresh" TEXT="刷新"/> </tb:TOOLBAR></body></html>三、数据的展示 *DataGrid改变选择行的颜色*A).cs类 private void DataGrid1_ItemDataBound(object sender,System.Web.UI.WebControls.DataGridItemEventArgs e) { if(e.Item.ItemType != ListItemType.Header) { string fID = e.Item.Cells[1].Text; // 这里的第一列为数据绑定中的ID值,通常是唯一标识 e.Item.Attributes.Add("id",fID); e.Item.Attributes.Add("onmouseover","sel('" + fID+ "')"); e.Item.Attributes.Add("onclick", "clicktr('" + fID+"')"); } }B)aspx文件 <script language="javascript"> var oid; function sel(id) // 鼠标移上去后执行 { document.getElementById(id).style.cursor='hand'; } function clicktr(id) { if(typeof(oid) != 'undefined') { document.getElementById(oid).style.background=''; } document.getElementById(id).style.background='#cccc66'; oid = id; } </script>四、无刷新的实现 *Ajax的应用*A)引用Ajax.dllB)web.config的<system.web>中增加 <!-- 对ajax支持 --> <httpHandlers> <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" /> </httpHandlers> C)cs类的page_load()中增加Ajax.Utility.RegisterTypeForAjax(typeof(类名));D)cs类中增加有Ajax.AjaxMethod()属性的方法,如: [Ajax.AjaxMethod()] public string Delete(string id) { return; }E)aspx文件脚本中增加调用方法和回调方法,如:function f_delete() { if(typeof(oid) != 'undefined') { if(confirm("确定要删除吗?")) { 类名.Delete(oid,f_delete_callback); } } else { alert("请选择要操作的行!"); } } //回调函数 function f_delete_callback(response) { if(response.error != null) { alert(response.error); return false; } var result = response.value; if(result != "") { alert("删除失败!"); } else { alert("删除成功!"); f_refresh(); } } CodeSmith 3.1 (.NET 1.1 / Visual Studio 2003)http://www.codesmithtools.com/download.aspx?key=a33ea36cd0JMail.Net 1.0(.NET 1.1)http://www.cnblogs.com/files/hotsoho.net/jmailnetfree.zip在线文本编辑器http://www.lionsky.net/MyWebsite/downsoft/index.aspx
转载于:https://www.cnblogs.com/hotsoho.net/archive/2006/03/11/348137.html