AJAX Control Toolkit——TextBoxWatermarkExtender(文本框提示效果)
该控件的效果就是在TextBox控件上添加“水印”效果,也就是当TextBox为空时,显示提示消息,当然你还可以为“水印”自定义CSS效果,一旦TextBox聚焦,样式就消失。
TextBoxWatermarkExtender
——TargetControlID,要添加效果的TextBox控件ID
——WatermarkText,当控件没有赋值时的提示文本
——WatermarkCssClass,应用于WatermarkText的样式
示例代码:(from Microsoft)
1 <asp:ScriptManager ID="ScriptManager1" runat="server" />
2 <div>
3 <br />
4 <asp:TextBox ID="TextBox1" runat="server" Width="289px"></asp:TextBox>
5 <br />
6 <br />
7 <asp:TextBox ID="TextBox2" runat="server" Width="289px"></asp:TextBox><br />
8 <br />
9 <asp:Button ID="Button1" runat="server" Text="Button" /><br />
10 <br />
11 <br />
12 <asp:TextBox ID="TextBox3" runat="server" Width="289px"></asp:TextBox><br />
13 <br />
14 <ajaxToolkit:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender1" runat="server"
15 TargetControlID="TextBox1" WatermarkCssClass="watermark" WatermarkText="Please enter a phone number (999) 000-1111">
16 </ajaxToolkit:TextBoxWatermarkExtender>
17 <br />
18 <ajaxToolkit:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender2" runat="server"
19 TargetControlID="TextBox2" WatermarkCssClass="watermark" WatermarkText="Enter anything">
20 </ajaxToolkit:TextBoxWatermarkExtender>
21 </div>
添加简单CSS:
.watermark
{
background: #FFAAFF;
}