Friday, December 19, 2008

Dot Net Tips n Tricks

1) To set the textbox's Text property having TextBoxMode property set to Password:
In case of normal textbox, we change its Text property by writing following code :



TextBox txtSample = new TextBox();
txtSample.Text = "Sample";


But in case if we are using textbox for Password purpose, then we have to set its TextBoxMode to Password. So to change its Text property we have to use following code:


TextBox txtPassword = new TextBox();
if (txtPassword.TextMode == TextBoxMode.Password)
{
//newValue is the new value that we want to set.
txtPassword.Attributes.Add("value", newValue);
}




2) Code to remove HTML contents from a string :


public string RemoveHTML(string strHTML)
{
//System.Web.HttpContext.Current.Server.HtmlDecode
return Server.HtmlDecode(Regex.Replace(strHTML, "<(.|\n)*?>", ""));
}

No comments:

Google