Sunday, September 18, 2011

Disable browser back button

Add the following code to the Page_Load event of ASP.NET web page

// Disable the Cache

Response.Buffer= true;
Response.ExpiresAbsolute=DateTime.Now.AddDays(-1d);
Response.Expires =-1500;
Response.CacheControl = "no-cache";
// Check for your SessionID
if(Session["SessionId"] == null)
{
   Response.Redirect ("Home.aspx");
}

Saturday, September 17, 2011

Calculate Processing Time in any Activity

Imports System.Diagnostics

Private Sub GetProcessTime()
Dim myWatchAs New Stopwatch
myWatch.Start()
Process_database()
myWatch.Stop()
MsgBox("Total Time Taken for Database Operation :
= " & myWatch.ElapsedMilliseconds.ToString)
End Sub

Friday, September 16, 2011

Validate URL

   Dim pattern As String = "^(http|https):/{2}[a-zA-Z./&\d_-]+"
        'create a new RegEx object
        Dim reg As New Regex(pattern, RegexOptions.IgnoreCase Or RegexOptions.ExplicitCapture)
        If reg.IsMatch(TextBox1.Text) = False Then
            MsgBox("invalid url!")
        Else
            MsgBox("valid url!")
        End If

Remove Multiple Spaces in Single Space

txtOutput.Text = Regex.Replace(txtInput.Text, "\s+", " ")