Monday, April 29, 2013

How To Localize Asp.Net Page Title

As we know, we use GetLocalResourceObject("ResourceName") to get local resource value from local resource file.
Or GetGlobalResourceObject("FileName", "Key") to get resource from global resource file.

In order to localize asp.net page title we should use meta:resourceKey like the following:
<%@ Page meta:resourcekey="PageTitle" %>
and in the resource file, we set PageTitle.Title to access Title value in the page.
and we cann't use GetLocalResourceObject("ResourceName") or GetGlobalResourceObject("FileName", "key") to localize page title in HTML, but you can use it in Code behinde.

Thursday, April 25, 2013

How to remove last character from string in C#

Suppose you have the following sentence:
"Riyadh - Jeddah - Dammam -"
which comes from list of cities and separated by (-) after each city.
you need to remove last separator.

just use the following code:

// remove last separator
 if (lblInputRegions.Text.EndsWith("-"))
         lblInputRegions.Text = lblInputRegions.Text.Remove((lblInputRegions.Text.Length - 1), 1);