Solution (1)
Script:
<Script type = "text/javascript" language = "javascript">
// Triggered when the focus is obtained
Function onFocusFun (element, elementValue ){
If (element. value = elementValue ){
Element. value = "";
Element. style. color = "";
}
}
// Triggered when the input box is left.
Function onblurFun (element, elementValue ){
If (element. value = ){
Element. style. color = "#808080 ";
Element. value = elementValue;
}
}
</Script>
Call example:
<Tr align = "center">
<Td style = "background-image: url(bg03.gif); background-position: center; background-repeat: no-repeat; height: 69px">
<Span style = "color: #000000; font-family: ;"> <strong> User name: </strong> </span> <asp: textbox id = "UserName" Text = "Enter the user name" runat = "server" Width = "100px" Height = "20px" ForeColor = "#808080"
OnFocus = "onFocusFun (this, enter the user name )"
OnBlur = "onblurFun (this, enter the user name)"> </asp: textbox>
<Br/>
<Span style = "color: #000000; font-family: ;"> <strong> password & nbsp; Code: </strong> </span> <asp: textbox id = "UserPass" runat = "server" Width = "100px" TextMode = "Password" Height = "20px"> </asp: textbox>
</Td>
</Tr>
Certificate --------------------------------------------------------------------------------------------------------------------------------------------
Solution 2)
[Method 1]
Front-end code:
<Div>
<Asp: TextBox ID = "txtName" runat = "server"> </asp: TextBox>
<Asp: TextBox ID = "txtPwd" runat = "server"> </asp: TextBox>
<Asp: Button ID = "btnLongin" runat = "server" Text = "Submit"/>
</Div>
Background code:
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Public partial class _ Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
// User input
TxtName. Attributes. Add ("Value", "enter user name ");
TxtName. Attributes. Add ("OnFocus", "if (this. value = enter the user name) {this. value = }");
TxtName. Attributes. Add ("OnBlur", "if (this. value =) {this. value = enter the user name }");
// Enter the password
TxtPwd. Attributes. Add ("Value", "Enter Password ");
TxtPwd. Attributes. Add ("OnFocus", "if (this. value = enter the password) {this. value = }");
TxtPwd. Attributes. Add ("OnBlur", "if (this. value =) {this. value = enter the password }");
//
If (! IsPostBack)
{
// Content
}
}
}
[Method 2]
Add the following two event attributes in the foreground text box:
OnFocus = "javascript: if (this. value = prompt text) {this. value = }"
OnBlur = "javascript: if (this. value =) {this. value = prompt text }"
----------------------------------- Example -----------------------------------------
<Asp: TextBox ID = "txtName" runat = "server" Text = "Enter the user name"
OnFocus = "javascript: if (this. value = enter the user name) {this. value = }"
OnBlur = "javascript: if (this. value =) {this. value = enter the user name}">
</Asp: TextBox>
<Asp: TextBox ID = "txtPwd" runat = "server" Text = "enter the password"
OnFocus = "javascript: if (this. value = enter the password) {this. value = }"
OnBlur = "javascript: if (this. value =) {this. value = enter the password}">
</Asp: TextBox>