首页 > 开发 > .Net > 正文

asp.net 编程 实用语句(6条)

2020-04-24 22:09:01
字体:
来源:转载
供稿:网友

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)

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表