該控制項的效果就是在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;
}