Thursday, April 23, 2009

Captilizing the first letter of all words in a sentence.

We need to capitalize the first letters of some word or some text (for example when we want to display users name or city name etc).
Since string class does not have a method to do this we could think that there is no built-in solution in C# for this problem...

But a little digging trough MSDN would help us find ToTitleCase method of TextInfo class in System.Globalization namespace that does exactly what we need: capitalizes the first letter of each word in the string.

here is how to use it:

using System.Globalization;

TextInfo UsaTextInfo = new CultureInfo("en-US", false).TextInfo;

string capitalized = UsaTextInfo.ToTitleCase("asp.net simply rocks!!!");


After the execution, capitalized string would have this value:
"Asp.Net Simply Rocks!!!".

Monday, April 20, 2009

Using body onload with ASP.net MasterPages

we want to use body onload tag in master pages but it will have effect other content pages.The onload function is for only one content page.for this purpose we have used below code in master page.
Master Page :
<script language="javascript">
function masterpage_onload()
{
if(window.content_onload != null)
window.content_onload();
//this condition check whether the rendered page has function are not.

}
</script>

Content Page :

<script language="javascript">
function content_onload()
{
//do something
}
</script>