Below is a simple example of Number Validation in Textbox of ASP.Net Using Regular Expression Validator.
It will also allow all decimal number, excluding all alphanumeric characters.
<asp:TextBox ID="AssetsTextBox" runat="server" Width="240px"></asp:TextBox>
<asp:RegularExpressionValidator ID="revAssets" runat="server"
ErrorMessage="Assets must be a number" Font-Bold="False"
Font-Size="Small"
ValidationExpression="^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$"
ControlToValidate="AssetsTextBox" Display="Dynamic" >
</asp:RegularExpressionValidator>
The .NET Framework allows developers to use the same set of skills to rapidly buid great applications for the web, windows, services and more.
Number Validation in Textbox of ASP.NET Using Regular Expression Validator
Display Text Upside down using CSS3
Below example will help you to learn how to Display some text Upside down on the webpage using CSS3.
<html>
<head>
<title>Display Text Up side down Example...</title>
<style type="text/css">
.displayUpsideDown
{
-o-transform: rotate(-180deg); /* Opera 10.5 */
-webkit-transform: rotate(-180deg); /* Safari 3.1+, Chrome */
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=2); /* IE6,IE7 */
ms-filter: "progid:DXImageTransform.Microsoft.BasicImage(rotation=2)"; /* IE8 */
-moz-transform: rotate(-180deg); /* FF3.5+ */
position: absolute;
}
</style>
</head>
<body>
<div class="displayUpsideDown">ENJOY SAMPLE TEXT HERE!!!</div>
</body>
</html>
ASP.NET MVC 3 Framework
Many people are searching for a BEST book for ASP.NET MVC 3 Frameowrk. I can guarantee you will enjoy reading below book for ASP.NET MVC 3 Framework.
http://www.amazon.com/gp/product/1430234040?ie=UTF8&tag=aspnettelligent-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=1430234040"
http://www.amazon.com/gp/product/1430234040?ie=UTF8&tag=aspnettelligent-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=1430234040"
Remove dots(.), hyphens(-), spaces,braces’(‘ and ‘)’ from string in C#
If you want to remove dots(.), hyphens(-), spaces, braces ‘(‘ and ‘)’ from a string in C# then you can use any solution given below.
string str = "A sample string having many . and ......It also has a hyphen (-) and too Many hyphens(------) Enjoy!!";
// Solution1: Use of String concat Function and Lambda Extension Method
var solution1 = string.Concat(str.Where(i => !new[] { '.', ' ', '-', '(', ')' }.Contains(i)));
Response.Write(solution1);
// Solution2: Use of Regular Expression. (Make sure you add using System.Text.RegularExpressions; on top of your page before using below solution2)
var solution2 = Regex.Replace(str, "[ ().-]+", "");
Response.Write(solution2);
// Solution3 : Use of Lambda and Extension Methods
var solution3 = str.ToCharArray().Where(i => i != ' ' && i != '-' && i != '.' && i != '(' && i != ')' ).Aggregate(" ", (a, b) => a + b);
Response.Write(solution3);
string str = "A sample string having many . and ......It also has a hyphen (-) and too Many hyphens(------) Enjoy!!";
// Solution1: Use of String concat Function and Lambda Extension Method
var solution1 = string.Concat(str.Where(i => !new[] { '.', ' ', '-', '(', ')' }.Contains(i)));
Response.Write(solution1);
// Solution2: Use of Regular Expression. (Make sure you add using System.Text.RegularExpressions; on top of your page before using below solution2)
var solution2 = Regex.Replace(str, "[ ().-]+", "");
Response.Write(solution2);
// Solution3 : Use of Lambda and Extension Methods
var solution3 = str.ToCharArray().Where(i => i != ' ' && i != '-' && i != '.' && i != '(' && i != ')' ).Aggregate(" ", (a, b) => a + b);
Response.Write(solution3);
Remove Duplicates From List in C#
To Remove Duplicates From List can be done by many different ways. You can use Distinct extension method to remove duplicates.
Below program that removes duplicates from the list in C#.
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
// List having duplicate integer elements.
List<int> list = new List<int>();
list.Add(7);
list.Add(2);
list.Add(5);
list.Add(5);
list.Add(2);
list.Add(3);
list.Add(7);
// Get distinct elements and convert again into a list.
List<int> distinct = list.Distinct().ToList();
foreach (int value in distinct)
{
Console.WriteLine("Distinct : {0}", value);
}
}
}
OR
You can use LINQ to object to remove duplicates from list,
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
// List having duplicate string elements.
List<string> list = new List<string>();
list.Add("A");
list.Add("A");
list.Add("C");
list.Add("D");
list.Add("B");
list.Add("A");
list.Add("E");
list.Add("E");
// Get distinct elements.
var distinct = (from item in list orderby item select item).Distinct();
foreach (string value in distinct)
{
Console.WriteLine("Distinct : {0}", value);
}
}
}
Below program that removes duplicates from the list in C#.
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
// List having duplicate integer elements.
List<int> list = new List<int>();
list.Add(7);
list.Add(2);
list.Add(5);
list.Add(5);
list.Add(2);
list.Add(3);
list.Add(7);
// Get distinct elements and convert again into a list.
List<int> distinct = list.Distinct().ToList();
foreach (int value in distinct)
{
Console.WriteLine("Distinct : {0}", value);
}
}
}
OR
You can use LINQ to object to remove duplicates from list,
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
// List having duplicate string elements.
List<string> list = new List<string>();
list.Add("A");
list.Add("A");
list.Add("C");
list.Add("D");
list.Add("B");
list.Add("A");
list.Add("E");
list.Add("E");
// Get distinct elements.
var distinct = (from item in list orderby item select item).Distinct();
foreach (string value in distinct)
{
Console.WriteLine("Distinct : {0}", value);
}
}
}
Sort Integer and String Array in C#
Example 1: Sort Int[] Array
This example int[] array that you have in your C# program. You can call static Array.Sort Method and use it to sort a integer array in place. The result is an ascending order of numbers.
using System;
using System.Collections.Generic;
using System.Text;
class Program
{
static void Main(string[] args)
{
int[] data = { 999,9,19,555,5,18,399};
Array.Sort(data);
foreach (int i in data)
Console.WriteLine(i);
Console.ReadLine();
}
}
Example 2: Sort string[] Array
This example string[] array that you have in your C# program. You can call static Array.Sort Method and use it to sort a string array in place. The result is an alphabetical sort.
using System;
class Program
{
static void Main()
{
string[] str = new string[]
{
"British",
"Indian",
"American",
"Chinese",
"Malaysians"
};
Array.Sort(str);
foreach (string s in str)
Console.WriteLine(s);
Console.ReadLine();
}
Example 3: Sort string Array with LINQ
This example string[] array that you have in your C# program. You can call static Array.Sort Method and use it to sort a string array in place. The result is an alphabetical sort. We will use LINQ query expression to order its contents.
using System;
using System.Linq;
class Program
{
static void Main()
{
string[] str = new string[]
{
"British",
"Indian",
"American",
"Chinese",
"Malaysians"
};
var sort = from s in str
orderby s
select s;
foreach (string c in sort)
Console.WriteLine(c);
Console.ReadLine();
}
}
Example 4: Sort string Array in reverse using LINQ
This example string[] array that you have in your C# program. You can call static Array.Sort Method and use it to sort a string array in place. The result is an alphabetical decending sort. We will use LINQ query expression to order its contents.
using System;
using System.Linq;
class Program
{
static void Main()
{
string[] str = new string[]
{
"British",
"Indian",
"American",
"Chinese",
"Malaysians"
};
var desc = from s in str
orderby s descending
select s;
foreach (string s in desc)
Console.WriteLine(s);
Console.ReadLine();
}
}
Example 5: Sort List
List<string> is a generic List collection of strings. It is stored as a string array. We can use LINQ exact same way we used in Example 3 and 4.
using System;
using System.Collections.Generic;class Program
{
static void Main()
{
List<string> lst = new List<string>()
{
"British",
"Indian",
"American",
"Chinese",
"Malaysians"
};
lst.Sort();
foreach (string s in lst)
Console.WriteLine(s);
Console.ReadLine();
}
}
This example int[] array that you have in your C# program. You can call static Array.Sort Method and use it to sort a integer array in place. The result is an ascending order of numbers.
using System;
using System.Collections.Generic;
using System.Text;
class Program
{
static void Main(string[] args)
{
int[] data = { 999,9,19,555,5,18,399};
Array.Sort(data);
foreach (int i in data)
Console.WriteLine(i);
Console.ReadLine();
}
}
Example 2: Sort string[] Array
This example string[] array that you have in your C# program. You can call static Array.Sort Method and use it to sort a string array in place. The result is an alphabetical sort.
using System;
class Program
{
static void Main()
{
string[] str = new string[]
{
"British",
"Indian",
"American",
"Chinese",
"Malaysians"
};
Array.Sort(str);
foreach (string s in str)
Console.WriteLine(s);
Console.ReadLine();
}
Example 3: Sort string Array with LINQ
This example string[] array that you have in your C# program. You can call static Array.Sort Method and use it to sort a string array in place. The result is an alphabetical sort. We will use LINQ query expression to order its contents.
using System;
using System.Linq;
class Program
{
static void Main()
{
string[] str = new string[]
{
"British",
"Indian",
"American",
"Chinese",
"Malaysians"
};
var sort = from s in str
orderby s
select s;
foreach (string c in sort)
Console.WriteLine(c);
Console.ReadLine();
}
}
Example 4: Sort string Array in reverse using LINQ
This example string[] array that you have in your C# program. You can call static Array.Sort Method and use it to sort a string array in place. The result is an alphabetical decending sort. We will use LINQ query expression to order its contents.
using System;
using System.Linq;
class Program
{
static void Main()
{
string[] str = new string[]
{
"British",
"Indian",
"American",
"Chinese",
"Malaysians"
};
var desc = from s in str
orderby s descending
select s;
foreach (string s in desc)
Console.WriteLine(s);
Console.ReadLine();
}
}
Example 5: Sort List
List<string> is a generic List collection of strings. It is stored as a string array. We can use LINQ exact same way we used in Example 3 and 4.
using System;
using System.Collections.Generic;class Program
{
static void Main()
{
List<string> lst = new List<string>()
{
"British",
"Indian",
"American",
"Chinese",
"Malaysians"
};
lst.Sort();
foreach (string s in lst)
Console.WriteLine(s);
Console.ReadLine();
}
}
Split String VB.NET Examples
How to Split String in VB.NET? There are different ways to call Split function in VB.NET. Below solutions guide you VB.NET Split string/sentence with examples.
Solution 1:
Simple Split Example. Below example uses Split on String.
' Input string
Dim str As String = "This is a test string"
' Split string based on spaces
Dim words As String() = str.Split(New Char() {" "c})
' Use For Each loop over words and display them. See the result below in Output.
Dim word As String
For Each word In words
Console.WriteLine(word)
Next
Solution 2:
Split Parts of a file path in VB.NET. Below example that splits file path.
' file system path we need to split
Dim str As String = "C:\Users\TestUser\Documents\Doc"
' Split the string on the backslash character (\)
Dim parts As String() = str.Split(New Char() {"\"c})
' Loop through result strings with For Each.
Dim part As String
For Each part In parts
Console.WriteLine(part)
Next
Solution 3:
Split string or sentence base on words in VB.NET
There are cases where you need to extract the words from a string/sentence in VB.NET. Below solution can handle non-word characters differently than the String Split method. For the same we need to use Regex.Split to parse the words in a string.
Add below line on top of your page.
Imports System.Text.RegularExpressions
Below code will splits words in VB.NET
Dim str As String
Dim arr As String() = SplitWordsInString("Oh! this is a simple task.")
For Each str In arr
Console.WriteLine(str)
Next
Console.ReadLine()
Private Function SplitWordsInString (ByVal str As String) As String()
Return Regex.Split(str, "\W+")
End Function
Solution 1:
Simple Split Example. Below example uses Split on String.
' Input string
Dim str As String = "This is a test string"
' Split string based on spaces
Dim words As String() = str.Split(New Char() {" "c})
' Use For Each loop over words and display them. See the result below in Output.
Dim word As String
For Each word In words
Console.WriteLine(word)
Next
Solution 2:
Split Parts of a file path in VB.NET. Below example that splits file path.
' file system path we need to split
Dim str As String = "C:\Users\TestUser\Documents\Doc"
' Split the string on the backslash character (\)
Dim parts As String() = str.Split(New Char() {"\"c})
' Loop through result strings with For Each.
Dim part As String
For Each part In parts
Console.WriteLine(part)
Next
Solution 3:
Split string or sentence base on words in VB.NET
There are cases where you need to extract the words from a string/sentence in VB.NET. Below solution can handle non-word characters differently than the String Split method. For the same we need to use Regex.Split to parse the words in a string.
Add below line on top of your page.
Imports System.Text.RegularExpressions
Below code will splits words in VB.NET
Dim str As String
Dim arr As String() = SplitWordsInString("Oh! this is a simple task.")
For Each str In arr
Console.WriteLine(str)
Next
Console.ReadLine()
Private Function SplitWordsInString (ByVal str As String) As String()
Return Regex.Split(str, "\W+")
End Function
ASP.NET Webservices - "The test form is only available for requests from the local machine."
Many times users get an error as "The test form is only available for requests from the local machine." when they try to invoke web service from remote machine.
To enable the Service to be invoked from remote machine, we need to add the following settings to the Web.Config file of the Web Service Application.
<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
This would enable the Web service to be able to be invoked from remote machine. However, this invoking would work only for simple data types and would not work in the case of complex datatypes.
To enable the Service to be invoked from remote machine, we need to add the following settings to the Web.Config file of the Web Service Application.
<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
This would enable the Web service to be able to be invoked from remote machine. However, this invoking would work only for simple data types and would not work in the case of complex datatypes.
Changing Master Page at Runtime
Solution 1:
Changing Master Page at Runtime by user code.
Many times we have to change Master Page at Runtime by user code. Page_PreInit event will execute just before that page is render. We can write a simple code in Page_PreInit event like below,
protected void Page_PreInit(object sender, EventArgs e)
{
if (Membership.GetUser() == null) //check if the user is logged in or not
this.MasterPageFile = "~/General.master";
else
this.MasterPageFile = "~/MyPortal.master";
}
Solution 2:
Changing Master Page at Runtime by user code based on users roles and responsibilities.
Sometimes there different types of users for the same application. All users have their own roles and responsibilities for the application.
For e.g There are different types of users for my portal application. They all should be able to browse their role related master page.
1. Executive Directors
2. Admin
3. Investment Officers
4. Users
For above portal application senerio we can write code in content Page_PreInit event like below,
protected void Page_PreInit(object sender, EventArgs e)
{
int varRole = 0;
int.TryParse(Session["Role"].ToString(),out varRole);
if (varRole == 1)
{
this.MasterPageFile = "ExecDir.master";
}
if (varRole == 2)
{
this.MasterPageFile = "Admin.master";
}
if (varRole == 3)
{
this.MasterPageFile = "Officer.master";
}
if (varRole == 4)
{
this.MasterPageFile = "User.master";
}
}
How to Rename a File
How to Rename a File? To Rename a file in C# is,
string path1 = @"c:\MyTest1.txt";
string path2 = @"c:\MyTest2.txt";
System.IO.File.Move(path1,path2);
To Rename a file in VB.Net is,
Dim path1 As String = "c:\MyTest1.txt"
Dim path2 As String = "c:\MyTest2.txt"
System.IO.File.Move(path1,path2)
string path1 = @"c:\MyTest1.txt";
string path2 = @"c:\MyTest2.txt";
System.IO.File.Move(path1,path2);
To Rename a file in VB.Net is,
Dim path1 As String = "c:\MyTest1.txt"
Dim path2 As String = "c:\MyTest2.txt"
System.IO.File.Move(path1,path2)
Clear All TextBoxes on a form
If you want to clear/Reset all Textboxes on a form, below solution will help you clear all Textboxes at a time.
You can write a simple funtion using below code,
public static void ClearAllTextBoxes(Control oControl)
{
foreach (Control ct in oControl.Controls)
{
if (ct is TextBox)
{
TextBox tb = (TextBox)ct.FindControl(ct.ID);
tb.Text = string.Empty;
}
if (ct.HasControls())
{
ClearAllTextBoxes(ct);
}
}
}
Call above Funtion using below code,
ClearAllTextBoxes(this);
You can write a simple funtion using below code,
public static void ClearAllTextBoxes(Control oControl)
{
foreach (Control ct in oControl.Controls)
{
if (ct is TextBox)
{
TextBox tb = (TextBox)ct.FindControl(ct.ID);
tb.Text = string.Empty;
}
if (ct.HasControls())
{
ClearAllTextBoxes(ct);
}
}
}
Call above Funtion using below code,
ClearAllTextBoxes(this);
WindowsIdentity.GetCurrent().Name in ASP.NET
You can use following code, if you want to know the user under which your ASP.NET application is running.
Add following namespace on top of your web page,
using System.Security.Principal;
Add following code to Page_Load event,
WindowsIdentity id = WindowsIdentity.GetCurrent();
Response.Write("Account Name: " + id.Name + "<br>");
Display Current Time on the web page
Below example helps you to display current time on the web page. Textbox value will be updated with the current time every second.
Add following code to the page,
<script type="text/javascript">
function DisplayTime()
{
var currentDate = new Date();
document.getElementById("<%= TextTime.ClientID %>").value = currentDate.toLocaleTimeString();
window.setTimeout("DisplayTime()", 1000);
}
</script>
<script type="text/javascript">
window.setTimeout("DisplayTime()", 1000);
</script>
<asp:TextBox ID="TextTime" runat="server"></asp:TextBox>
Javascript Alert message from code behind in ASP.NET
We all know that we can display javascript alert message from code behind in ASP.NET using Page.ClientScript.RegisterStartupScript.
Page.ClientScript.RegisterStartupScript(this.GetType(),"myscript","alert('hello world!');");
However, above method can break under ASP.NET AJAX environment. For AJAX we need to use ScriptManager.RegisterStartupScript. Below code displays javascript alert message both in AJAX environment and on regular page as well.
ScriptManager.RegisterStartupScript(this,this.GetType(),"myscript","alert('hello world!');",true);
For more information on ClientScriptManager.RegisterStartupScript Method you can visit,
Space Example in VB.NET
If you want to return a string that contains the specified numbers of spaces or if you want to append a number with specified number of spaces then below example will help you solve the problem.
You can use below code too if you want to append or add blank spaces to the right of the string or number.
Dim part2 as Integer
Dim part3 As String
part2 = 12345
part3 = part2.ToString() + Space(5)
MsgBox(part3.Length())
Above example will add 5 blank spaces to the number 12345. So the Length of the number is 10 and the messagebox will return 10.
You can use below code too if you want to append or add blank spaces to the right of the string or number.
Dim part2 as Integer
Dim part3 As String
part2 = 12345
part3 = part2.ToString() + Space(5)
MsgBox(part3.Length())
Above example will add 5 blank spaces to the number 12345. So the Length of the number is 10 and the messagebox will return 10.
Open a new Window in JavaScript
How to Open a new Window in Javascript/using Javascript is easy. Copy below code in your page.
If you want to open a new window on button clik then use below code,
<input type="button" value="Open New Window" onClick="OpenNewWindow('http://www.google.com')" />
If you want to open a new window using hyperlink then use below code,
<a href="javascript:OpenNewWindow('http://www.google.com/')">Open Google</a>
Copy below javascript code between your <head> and </head> tags on the page.
<script type="text/javascript">
function OpenNewWindow(url)
{
newwindow = window.open(url, 'mywindow', 'width=600,height=700');
newwindow.focus();
}
</script>
If you want to open a new window on button clik then use below code,
<input type="button" value="Open New Window" onClick="OpenNewWindow('http://www.google.com')" />
If you want to open a new window using hyperlink then use below code,
<a href="javascript:OpenNewWindow('http://www.google.com/')">Open Google</a>
Copy below javascript code between your <head> and </head> tags on the page.
<script type="text/javascript">
function OpenNewWindow(url)
{
newwindow = window.open(url, 'mywindow', 'width=600,height=700');
newwindow.focus();
}
</script>
Display Textbox count on a Label
This solution will help you use asp Text box and a Label to display the count of characters,
Add below code on your Default.aspx,
<asp:TextBox ID="txtComments" runat="server" TextMode="MultiLine"
MaxLength="160" ></asp:TextBox>
<asp:Label ID="lblCharacters" runat="server"></asp:Label>
Add below javascript code on your default.aspx,
<script language="javascript" type="text/javascript">
function DisplayCount()
{
var length = document.getElementById('<%=txtComments.ClientID%>').value.length;
document.getElementById('<%=lblCharacters.ClientID%>').innerText = length;
}
</script>
Add following code on your Page_load event,
txtComments.Attributes.Add("onkeypress", "javascript:return DisplayCount();");
After adding above code, you can see the count on the label when you type in the textbox.
Disable Right click on web page
How to disable right click on web page or If you want to protect your source code or many times programmers may need to disable right click on web page. You can copy below script code in between <head> and </head> tag.
<script type="text/javascript">
var message="You Can't right click on this page!";
function clickIE()
{
if (event.button==2)
{
alert(message);
return false;
}
}
if (document.all&&!document.getElementById)
{
document.onmousedown=clickIE;
}
document.oncontextmenu=new Function("alert(message);return false")
</script>
Get Assembly Name
Sometimes you are asked to get/find Assembly name of a class.
You can use below code to get/find Assembly Name in VB.Net,
Dim assembly As System.Reflection.Assembly = System.Reflection.Assembly.GetAssembly(GetType(Class1))
Response.Write(assembly.GetName().Name)
You can use below code to get/find Assembly Name in C#,
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetAssembly(typeof(Class1));
Response.Write(assembly.GetName().Name);
Here in above code Assembly.GetAssembly Method gets the currently loaded assembly in which the specified class is defined.
You can use below code to get/find Assembly Name in VB.Net,
Dim assembly As System.Reflection.Assembly = System.Reflection.Assembly.GetAssembly(GetType(Class1))
Response.Write(assembly.GetName().Name)
You can use below code to get/find Assembly Name in C#,
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetAssembly(typeof(Class1));
Response.Write(assembly.GetName().Name);
Here in above code Assembly.GetAssembly Method gets the currently loaded assembly in which the specified class is defined.
DateTime in different formats
Using DateTime.Tostring() method, you can display Date and/or Time based on your requirement.
Find the code below displaying Date in 24 different formats.
Response.Write("Displaying DateTime in 24 Different Formats....");
strFormat = dt.ToString("MM/dd/yyyy");
Response.Write("Format 1: " + strFormat);
strFormat = dt.ToString("dddd, dd MMMM yyyy");
Response.Write("Format 2: " + strFormat);
strFormat = dt.ToString("dddd, dd MMMM yyyy HH:mm");
Response.Write("Format 3: " + strFormat);
strFormat = dt.ToString("dddd, dd MMMM yyyy hh:mm tt");
Response.Write("Format 4: " + strFormat);
strFormat = dt.ToString("dddd, dd MMMM yyyy H:mm");
Response.Write("Format 5: " + strFormat);
strFormat = dt.ToString("dddd, dd MMMM yyyy h:mm tt");
Response.Write("Format 6: " + strFormat);
strFormat = dt.ToString("dddd, dd MMMM yyyy HH:mm:ss");
Response.Write("Format 7: " + strFormat);
strFormat = dt.ToString("MM/dd/yyyy HH:mm");
Response.Write("Format 8: " + strFormat);
strFormat = dt.ToString("MM/dd/yyyy hh:mm tt");
Response.Write("Format 9: " + strFormat);
strFormat = dt.ToString("MM/dd/yyyy H:mm");
Response.Write("Format 10: " + strFormat);
strFormat = dt.ToString("MM/dd/yyyy h:mm tt");
Response.Write("Format 11: " + strFormat);
strFormat = dt.ToString("MM/dd/yyyy HH:mm:ss");
Response.Write("Format 12: " + strFormat);
strFormat = dt.ToString("MMMM dd");
Response.Write("Format 13: " + strFormat);
strFormat = dt.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK");
Response.Write("Format 14: " + strFormat);
strFormat = dt.ToString("ddd, dd MMM yyyy HH':'mm':'ss 'GMT'");
Response.Write("Format 15: " + strFormat);
strFormat = dt.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss");
Response.Write("Format 16: " + strFormat);
strFormat = dt.ToString("HH:mm");
Response.Write("Format 17: " + strFormat);
strFormat = dt.ToString("hh:mm tt");
Response.Write("Format 18: " + strFormat);
strFormat = dt.ToString("H:mm");
Response.Write("Format 19: " + strFormat);
strFormat = dt.ToString("h:mm tt");
Response.Write("Format 20: " + strFormat);
strFormat = dt.ToString("HH:mm:ss");
Response.Write("Format 21: " + strFormat);
strFormat = dt.ToString("yyyy'-'MM'-'dd HH':'mm':'ss'Z'");
Response.Write("Format 22: " + strFormat);
strFormat = dt.ToString("dddd, dd MMMM yyyy HH:mm:ss");
Response.Write("Format 23: " + strFormat);
strFormat = dt.ToString("yyyy MMMM");
Response.Write("Format 24: " + strFormat);
Find the code below displaying Date in 24 different formats.
Response.Write("Displaying DateTime in 24 Different Formats....");
strFormat = dt.ToString("MM/dd/yyyy");
Response.Write("Format 1: " + strFormat);
strFormat = dt.ToString("dddd, dd MMMM yyyy");
Response.Write("Format 2: " + strFormat);
strFormat = dt.ToString("dddd, dd MMMM yyyy HH:mm");
Response.Write("Format 3: " + strFormat);
strFormat = dt.ToString("dddd, dd MMMM yyyy hh:mm tt");
Response.Write("Format 4: " + strFormat);
strFormat = dt.ToString("dddd, dd MMMM yyyy H:mm");
Response.Write("Format 5: " + strFormat);
strFormat = dt.ToString("dddd, dd MMMM yyyy h:mm tt");
Response.Write("Format 6: " + strFormat);
strFormat = dt.ToString("dddd, dd MMMM yyyy HH:mm:ss");
Response.Write("Format 7: " + strFormat);
strFormat = dt.ToString("MM/dd/yyyy HH:mm");
Response.Write("Format 8: " + strFormat);
strFormat = dt.ToString("MM/dd/yyyy hh:mm tt");
Response.Write("Format 9: " + strFormat);
strFormat = dt.ToString("MM/dd/yyyy H:mm");
Response.Write("Format 10: " + strFormat);
strFormat = dt.ToString("MM/dd/yyyy h:mm tt");
Response.Write("Format 11: " + strFormat);
strFormat = dt.ToString("MM/dd/yyyy HH:mm:ss");
Response.Write("Format 12: " + strFormat);
strFormat = dt.ToString("MMMM dd");
Response.Write("Format 13: " + strFormat);
strFormat = dt.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK");
Response.Write("Format 14: " + strFormat);
strFormat = dt.ToString("ddd, dd MMM yyyy HH':'mm':'ss 'GMT'");
Response.Write("Format 15: " + strFormat);
strFormat = dt.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss");
Response.Write("Format 16: " + strFormat);
strFormat = dt.ToString("HH:mm");
Response.Write("Format 17: " + strFormat);
strFormat = dt.ToString("hh:mm tt");
Response.Write("Format 18: " + strFormat);
strFormat = dt.ToString("H:mm");
Response.Write("Format 19: " + strFormat);
strFormat = dt.ToString("h:mm tt");
Response.Write("Format 20: " + strFormat);
strFormat = dt.ToString("HH:mm:ss");
Response.Write("Format 21: " + strFormat);
strFormat = dt.ToString("yyyy'-'MM'-'dd HH':'mm':'ss'Z'");
Response.Write("Format 22: " + strFormat);
strFormat = dt.ToString("dddd, dd MMMM yyyy HH:mm:ss");
Response.Write("Format 23: " + strFormat);
strFormat = dt.ToString("yyyy MMMM");
Response.Write("Format 24: " + strFormat);
Subscribe to:
Posts (Atom)