Trace的基本用法(調試技術)

來源:互聯網
上載者:User
前台

  1. <%@ Page Trace="false" Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" >
  4. <head runat="server">
  5.     <title>Trace的基本用法</title>
  6. </head>
  7. <body>
  8.     <form id="form1" runat="server">
  9.     <div>
  10.         <asp:label ID="Label1" runat="server" Text="Tracing,Debuging & Error Handling Demo"></asp:label><br />
  11.         <asp:dropdownlist ID="ddlBooks" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlBooks_SelectedIndexChanged">
  12.         </asp:dropdownlist><br />
  13.         <asp:label ID="lblDdl" runat="server" Text="Label"></asp:label>
  14.         <br />
  15.         <asp:hyperlink ID="HyperLink1" runat="server" NavigateUrl="Test.aspx">LinkTo</asp:hyperlink></div>
  16.     </form>
  17. </body>
  18. </html>

後台

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Web.UI.HtmlControls;
  10. public partial class _Default : System.Web.UI.Page 
  11. {
  12.     protected void Page_Load(object sender, EventArgs e)
  13.     {
  14.         Trace.Write("in page_load");
  15.         if (!IsPostBack)
  16.         {
  17.             Trace.Write("page_load", "not postback");
  18.             string[,] books ={ 
  19.             {"書名0","0"},
  20.             {"書名1","1"},
  21.             {"書名2","2"}
  22.             };
  23.             int i;
  24.             for (i = 0; i < books.GetLength(0); i++)
  25.             {
  26.                 ddlBooks.Items.Add(new ListItem(books[i, 0], books[i, 1]));
  27.             }
  28.         }
  29.     }
  30.     protected void ddlBooks_SelectedIndexChanged(object sender, EventArgs e)
  31.     {
  32.         try
  33.         {
  34.             int a = 0;
  35.             int b = 5 / a;
  36.         }
  37.         catch (System.Exception ex)
  38.         {
  39.             Trace.Warn("useraction", "calling b=5/a", ex);
  40.         }
  41.         if (ddlBooks.SelectedIndex != -1)
  42.         { 
  43.             lblDdl.Text=ddlBooks.SelectedItem.Text+"--->ISBN:"+ddlBooks.SelectedValue;
  44.         }
  45.     }
  46. }

 結束

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.