SoFunction
Updated on 2025-04-09

Thirty-three commonly used codes page 2/7


8. About date format
Date format setting
DataFormatString="{0:yyyy-MM-dd}" 
I think it should be in the itembound event
["Your Column"].text=(["Your Column"].("yyyy-MM-dd"))
9. Get the error message and go to the specified page
Don't use it, but use it
 
// in  
protected void Application_Error(Object sender, EventArgs e) { 
if (() is HttpUnhandledException) 
(""); 
//Leave the other non-HttpUnhandledException exceptions to yourself to handle and it's OK :)

Redirect will cause post-back to generate and lose error information, so page guidance should be executed directly on the server side, so that error information can be obtained on the error handling page and processed accordingly.
10. Clear cookies
=[DateTime]; 
("UserName").Expires = 0 
11. Custom exception handling
//Custom exception handling class
using System; 
using ; 
namespace MyAppException 

 /// <summary> 
/// Application exception handling class inherited from system exception class ApplicationException.
/// Automatically record exception content to the application log of Windows NT/2000
 /// </summary> 
 public class AppException: 
 { 
public AppException() 

if ()LogEvent("An unknown error occurred.");

 public AppException(string message) 
 { 
LogEvent(message); 
 } 
 public AppException(string message,Exception innerException) 
 { 
LogEvent(message); 
if (innerException != null) 

 LogEvent(); 

 } 
//Log recording class
 using System; 
 using ; 
 using ; 
 using ; 
 using ; 
 using ; 
 namespace MyEventLog 
 { 
/// <summary> 
/// Event logging class, providing event logging support
/// <remarks> 
/// Define 4 logging methods (error, warning, info, trace)
/// </remarks> 
/// </summary> 
public class ApplicationLog 

 /// <summary> 
/// Log the error message to the Win2000/NT event log
/// <param name="message">Text information that needs to be recorded</param>
 /// </summary> 
 public static void WriteError(String message) 
 { 
WriteLog(, message); 
 } 
 /// <summary> 
/// Record the warning information to the Win2000/NT event log
/// <param name="message">Text information that needs to be recorded</param>
 /// </summary> 
 public static void WriteWarning(String message) 
 { 
WriteLog(, message); 
 } 
 /// <summary> 
/// Record the prompt information to the Win2000/NT event log
/// <param name="message">Text information that needs to be recorded</param>
 /// </summary> 
 public static void WriteInfo(String message) 
 { 
WriteLog(, message); 
 } 
 /// <summary> 
/// Record the tracking information to the Win2000/NT event log
/// <param name="message">Text information that needs to be recorded</param>
 /// </summary> 
 public static void WriteTrace(String message) 
 { 
WriteLog(, message); 
 } 
 /// <summary> 
/// Format the text information format recorded to the event log
/// <param name="ex">Exception object that needs to be formatted</param>
/// <param name="catchInfo">Exception information title string.</param>
 /// <retvalue> 
/// Exception information string in the format of <para>, including exception content and tracking stack. </para>
 /// </retvalue> 
 /// </summary> 
 public static String FormatException(Exception ex, String catchInfo) 
 { 
StringBuilder strBuilder = new StringBuilder(); 
if (catchInfo != ) 

 (catchInfo).Append("\r\n"); 

().Append("\r\n").Append(); 
return (); 
 } 
 /// <summary> 
/// Actual event log writing method
/// <param name="level">The level of information to be recorded (error, warning, info, trace).</param>
/// <param name="messageText">The text to be recorded.</param>
 /// </summary> 
 private static void WriteLog(TraceLevel level, String messageText) 
 { 
try 

 EventLogEntryType LogEntryType; 
 switch (level) 
 { 
case : 
 LogEntryType = ; 
 break; 
case : 
 LogEntryType = ; 
 break; 
case : 
 LogEntryType = ; 
 break; 
case : 
 LogEntryType = ; 
 break; 
default: 
 LogEntryType = ; 
 break; 
 } 
 EventLog eventLog = new EventLog("Application", ,  ); 
//Write to event log
 (messageText, LogEntryType); 

catch {} //Ignore any exceptions

 } //class ApplicationLog 

Previous page1234567Next pageRead the full text