Sunday, March 18, 2007

Apply Unicode in your website

1. To install Unicode into you Web page, you need to add the underlined lines in your HEAD section:
<html>
<head>
<title> Your Web page Title </title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
</head>
2. In the BODY section, to display Unicode font as you like it, you need to add <font face="xxxxx" ......> in which xxxxx is one of Unicode names as following: Arial, Courier News, Tahoma, Times New Roman and Verdana. Moreover, you must convert your text into Unicode format to paste them in the content of your web page.
<body>
<font face="Arial" size="5"> இது தமிழ் மொழி </font>
</body>
</html>

What is RegEx (Regular Expression) ?


Regular expressions are a language that can be used to explicitly describe patterns within strings of text. In addition to simply describing such patterns, regular expression engines can typically be used to iterate through matches, to parse strings into substrings using patterns as delimiters, or to replace or reformat text in an intelligent fashion. They provide a powerful and usually very succinct way to solve many common tasks related to text manipulation.

Quantifiers

1. *, which describes "0 or more occurrences"
2. +, which describes "1 or more occurrences"
3. ?, which descirbes "0 or 1 occurrence

Explicit quantifiers use curly braces {} and number values for upper and lower occurrence limits within the braces.
eg:
ab{2}c abbc, aaabbccc

for more details please visit the following url
http://msdn2.microsoft.com/en-us/library/ms972966.aspx

Need more examples visit http://www.regular-expressions.info/
Get Client Machine IP Address


string strIP= Request.ServerVariables["REMOTE_ADDR"]

string strIP1= Request.UserHostAddress;

Wednesday, March 14, 2007

Resize an Array (ASP.NET)



Following example describes how to resize an array

Dim str(10) As String

str(0) = "a"
str(1) = "b"
str(2) = "c"
str(3) = "d"
Response.Write(UBound(str) & "<br>")
Array.Resize(str, 4)
Response.Write(UBound(str) & "<br>")
Run a batch file through ASP.NET


This is a sample program for running a batch file using asp.net


Imports System.Diagnostics

Partial Class testing
Inherits System.Web.UI.Page

Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim p As New ProcessStartInfo
p.WorkingDirectory = "c:\"
p.FileName = "p.bat"
p.UseShellExecute = True
Process.Start(p)
End Sub
End Class

Create "p.bat" and a.txt file in C directory and "p.bat" file contains the following code

ren a.txt b.txt
pause
Email validation Using ASP.NET

Dim strRegexEmail As String = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" & _
"\.[0-9]{1,3}\.[0-9]{1,3}\.)(([a-zA-Z0-9\-]+\" & _
".)+))([a-zA-Z]{2,4}[0-9]{1,3})(\]?)$"

Dim re As New Regex(strRegexEmail)


If Not re.IsMatch(txtEmail.Text) And Trim(txtEmail.Text) <> "" Then
ClientErrorMSG = "Email Address is Invalid"
txtEmail.Focus()
End If

Getting Error '0.cells' is null or not an object, when menu is inside of UpdatePanel


Keep menu outside of update panel and configure the trigger property as the following example code.


<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Menu1" EventName="MenuItemClick" />
</Triggers>
</asp:UpdatePanel>

<asp:Menu ID="Menu1" runat="server" BackColor="#F7F6F3" DynamicHorizontalOffset="2"
Font-Names="Verdana" Font-Size="Small" ForeColor="#7C6F57" OnMenuItemClick="Menu1_MenuItemClick"
StaticSubMenuIndent="10px" Width="150px">
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicHoverStyle BackColor="#7C6F57" ForeColor="White" />
<DynamicMenuStyle BackColor="#F7F6F3" />
<StaticSelectedStyle BackColor="#5D7B9D" />
<DynamicSelectedStyle BackColor="#5D7B9D" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<Items>
<asp:MenuItem Text="Save" Value="Save"></asp:MenuItem>
<asp:MenuItem Text="New" Value="New"></asp:MenuItem>
</Items>