分享

asp.net编程中6条实用语句

 悟静 2010-07-03
1.Panel 横向滚动,纵向自动扩展 
<asp:panel style="overflow-x:scroll;overflow-y:auto;"></asp:panel> 
2.回车转换成Tab 
(1) 
<script language="javascript" for="document" event="onkeydown"> 
  if(event.keyCode==13 && event.srcElement.type!=’button’ && event.srcElement.type!=’submit’ &&     event.srcElement.type!=’reset’ && event.srcElement.type!=’’&& event.srcElement.type!=’textarea’); 
  event.keyCode=9; 
</script> 
(2)  //当在有keydown事件的控件上敲回车时,变为tab 
public void Tab(System.Web .UI.WebControls .WebControl webcontrol) 

webcontrol.Attributes .Add ("onkeydown", "if(event.keyCode==13) event.keyCode=9"); 
3.DataGrid超级连接列 
DataNavigateUrlField="字段名" DataNavigateUrlFormatString="http://xx/inc/delete.aspx?ID={0}" 
4.自定义异常处理 
//自定义异常处理类 
using System; 
using System.Diagnostics; 
namespace MyAppException 

  /// <summary> 
  /// 从系统异常类ApplicationException继承的应用程序异常处理类。 
  /// 自动将异常内容记录到Windows NT/2000的应用程序日志 
  /// </summary> 
  public class AppException:System.ApplicationException 
  { 
  public AppException() 
  { 
  if (ApplicationConfiguration.EventLogEnabled)LogEvent("出现一个未知错误。"); 
  } 
  public AppException(string message) 
  { 
  LogEvent(message); 
  } 
  public AppException(string message,Exception innerException) 
  { 
  LogEvent(message); 
  if (innerException != null) 
  { 
  LogEvent(innerException.Message); 
  } 
  } 
  //日志记录类 
  using System; 
  using System.Configuration; 
  using System.Diagnostics; 
  using System.IO; 
  using System.Text; 
  using System.Threading; 
  namespace MyEventLog 
  { 
  /// <summary> 
  /// 事件日志记录类,提供事件日志记录支持 
  /// <remarks> 
  /// 定义了4个日志记录方法 (error, warning, info, trace) 
  /// </remarks> 
  /// </summary> 
  public class ApplicationLog 
  { 
  /// <summary> 
  /// 将错误信息记录到Win2000/NT事件日志中 
  /// <param name="message">需要记录的文本信息</param> 
  /// </summary> 
  public static void WriteError(String message) 
  { 
  WriteLog(TraceLevel.Error, message); 
  } 
  /// <summary> 
  /// 将警告信息记录到Win2000/NT事件日志中 
  /// <param name="message">需要记录的文本信息</param> 
  /// </summary> 
  public static void WriteWarning(String message) 
  { 
  WriteLog(TraceLevel.Warning, message);   
  } 
  /// <summary> 
  /// 将提示信息记录到Win2000/NT事件日志中 
  /// <param name="message">需要记录的文本信息</param> 
  /// </summary> 
  public static void WriteInfo(String message) 
  { 
  WriteLog(TraceLevel.Info, message); 
  }
本文来自: 网页设计大本营(www.) 详细出处参考:http://www./html/20081227123313580.html

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约