ASPNET程序中常用的三十三种代码剖析

上传人:m**** 文档编号:504213443 上传时间:2022-10-08 格式:DOCX 页数:26 大小:175.82KB
返回 下载 相关 举报
ASPNET程序中常用的三十三种代码剖析_第1页
第1页 / 共26页
ASPNET程序中常用的三十三种代码剖析_第2页
第2页 / 共26页
ASPNET程序中常用的三十三种代码剖析_第3页
第3页 / 共26页
ASPNET程序中常用的三十三种代码剖析_第4页
第4页 / 共26页
ASPNET程序中常用的三十三种代码剖析_第5页
第5页 / 共26页
点击查看更多>>
资源描述

《ASPNET程序中常用的三十三种代码剖析》由会员分享,可在线阅读,更多相关《ASPNET程序中常用的三十三种代码剖析(26页珍藏版)》请在金锄头文库上搜索。

1、1 .打开新的窗口并传送参数:传送参数:“)response.write(vscriptwindow.open(*.aspx?id=+this.DropDownList1.SelectIndex+&id1=+.+”接收参数:stringa=Request.QueryString(id);stringb=Request.QueryString(id1);2 .为按钮添加对话框Button1.Attributes.Add(onclick,returnconfirm(确认?);button.attributes.add(onclick,if(confirm(yousure.?are)rettrrre

2、;elsereturnfalse;)3 .删除表格选定记录intintEmpID=(int)MyDataGrid.DataKeyse.Item.ItemIndex;stringdeleteCmd=DeletefromEmployeewhereemp_id=+intEmpID.ToString()4 .删除表格记录警告privatevoidDataGrid_ItemCreated(Objectsender,DataGridItemEventArgse)switch(e.Item.ItemType)caseListItemType.ItemcaseListItemType.AlternatingI

3、temcaseListItemType.EditItem:TableCellmyTableCell;myTableCell=e.Item.Cells14;LinkButtonmyDeleteButton;myDeleteButton=(LinkButton)myTableCell.Controls0;myDeleteButton.Attributes.Add(onclick,returnconfirm(您是否确定要删除这条信息););break;default:break;5 .点击表格行链接另一页privatevoidgrdCustomer_ItemDataBound(objectsende

4、r,System.Web.UI.WebControls.DataGridltemEventArgse)点击表格打开if(e.Item.ItemType=ListItemType.Item|e.Item.ItemType=ListItemType.AlternatingItem)e.Item.Attributes.Add(onclick,window.open(Default.aspx?ide=.tem.Cells0.Text+););双击表格连接到另一页在itemDataBind事件中if(e.Item.ItemType=ListItemType.Item|e.Item.ItemType=Li

5、stItemType.AlternatingItem)stringorderItemID=e.item.cells1.Text;.e.item.Attributes.Add(ondblclick,location.href=./ShippedGrid.aspx?id=orderItemID+);双击表格打开新一页if(e.Item.ItemType=ListItemType.Item|e.Item.ItemType=ListItemType.AlternatingItem)stringorderItemID=e.item.cells1.Text;.e.item.Attributes.Add(o

6、ndblclick,open(./ShippedGrid.aspx?id=+orderItemID+);6 .表格超连接列传递参数vasp:HyperLinkColumnTarget=_blankheadertext=ID号DataTextField=idNavigateUrl=aaa.aspx?id=%#DataBinder.Eval(Container.DataItem,数据字段1)%&name=v%#DataBinder.Eval(Container.DataItem,数据字段2)%7 .表格点击改变颜色if(e.Item.ItemType=ListItemType.Item|e.Ite

7、m.ItemType=ListItemType.AlternatingItem)e.Item.Attributes.Add(onclick,this.style.backgroundColor=#99cc00;this.style.color=buttontext;this.style.cursor=default;);if(e.Item.ItemType=ListItemType.Item|e.Item.ItemType=ListItemType.AlternatingItem)e.Item.Attribut es.Add(onmouseover,this.style.backgroundC

8、olor=this.style.color=buttontext ;this.style.cursor=e.Item.Attributes.Add(onmouseout,this.style.backgroundColor=#99cc00 ;default ;);this.style.color=8 .关于日期格式日期格式设定DataFormatString=0:yyyy-MM-dd”我觉得应该在itembound事件中e.items.cell你的列.text=DateTime.Parse(e.items.cell你的列.text.ToString(yyyy-MM-dd)9获取错误信息并到指定

9、页面不要使用Response.Redirect,而应该使用Server.Transfere.g/inglobal.asaxprotectedvoidApplication_Error(Objectsender,EventArgse)if(Server.GetLastError()isHttpUnhandledException)Server.Transfer(MyErrorPage.aspx);/其余白勺非HttpUnhandledException异常交给ASP.NET自己处理就okay了:)ect会导致post-back的产生从而丢失了错误信息,所以页面导向应该直接在服务器端执行,这样就可

10、以在错误处理页面得到出错信相应的处理10 .清空CookieCookie.Expires=DateTime;Response.Cookies(UserName).Expires=011 .自定义异常处理自定义异常处理类usingSystem;usingSystem.Diagnostics;namespaceMyAppException/从系统异常类ApplicationException继承的应用程序异常处理类。/自动将异常内容记录到WindowsNT/2000的应用程序日志/publicclassAppException:System.ApplicationException);public

11、AppException()if(ApplicationConfiguration.EventLogEnabled)LogEvent(出现一个未知错误。publicAppException(stringmessage)LogEvent(message);publicAppException(stringmessage,ExceptioninnerException)LogEvent(message);if(innerException!=null)LogEvent(innerException.Message);日志记录类usingSystem;usingSystem.Configuratio

12、n;usingSystem.Diagnostics;usingSystem.IO;usingSystem.Text;usingSystem.Threading;namespaceMyEventLog111 susummaryIII事件日志记录类,提供事件日志记录支持IllreremarksIll定义了4个日志记录方法(error,warning,info,trace)IIIIllpublicclassApplicationLogIllsummaryIll将错误信息J己录到Win2000INT事件日志中IllvparamnameTmessageHAfPli己的彳百息、vlparamIllpubl

13、icstaticvoidWriteError(Stringmessage)WriteLog(TraceLevel.Error,message);IllsummaryIll将警告信息J己录到Win2000INT事件日志中IllvparamnameimessageAfPli己的彳百息、vlparamIllpublicstaticvoidWriteWarning(Stringmessage)WriteLog(TraceLevel.Warning,message);IllsummaryIll将提示信息J己录到Win2000INT事件日志中IllvparamnameimessageAfPli己的彳百息、

14、vlparamIllpublicstaticvoidWriteInfo(Stringmessage)WriteLog(TraceLevel.Info,message);IllsummaryIll将跟踪信息J己录到Win2000INT事件日志中IllvparamnameimessageAfPli己的彳百息、vlparamIllpublicstaticvoidWriteTrace(Stringmessage)WriteLog(TraceLevel.Verbose,message);/summary/格式化记录到事件日志的文本信息格式/vparamname=ex”需要格式化的异常对象v/param/异常信息标题字符串.v/param/vpara格式后的异常信息字符串,包括异常内容和跟踪堆栈v/para/publicstaticStringFormatException

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 营销创新

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号