Data Browser - Viewing Site  Sector 23 Code Bank Logged in as:  Guest  




           


Add Placeholder Text to a .NET Login Control
To add Placeholder Text to a .NET Login Control:

1. Declare an extension method in a control helper class

/// <summary>
/// Define HTML5 placeholder text on a textbox.
/// Older browsers ignore this property.
/// </summary>
/// <param name="txt"></param>
/// <param name="placeholderText"></param>
public static void SetPlaceholderText(this TextBox txt, string placeholderText)
{
txt.Attributes["placeholder"] = placeholderText;
}

2. Call the method from your asp:Login control's two textboxes:

var txt = myLogin.FindControl("UserName") as TextBox;
if (txt != null)
txt.SetPlaceholderText("User Name");
var pwd = LoginBox.FindControl("Password") as TextBox;
if (pwd != null)
pwd.SetPlaceholderText("Password");

Created By: amos 3/10/2015 2:56:25 PM
Updated: 3/10/2015 2:57:21 PM