Вопрос

i use this code in aspx page:

<asp:TextBox ID="Search" runat="server" ToolTip="Search..." Text="Search..." onblur="if (this.value=='') this.value='Search...';" onfocus="if (this.value=='Search...') this.value='';"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvSearch" runat="server" ControlToValidate="Search" ErrorMessage="please insert text" ValidationGroup="Search" SetFocusOnError="True" Display="None"></asp:RequiredFieldValidator>

but i use Text="Search" in textbox for use Watermark property in textbox. please help me for use property and RequiredFieldValidator.

Это было полезно?

Решение

You could set InitialValue = "Search..."

<asp:RequiredFieldValidator ID="rfvSearch" runat="server" 
    ControlToValidate="Search" ErrorMessage="please insert text" 
    ValidationGroup="Search" SetFocusOnError="True" Display="None"
    InitialValue="Search...">
</asp:RequiredFieldValidator>

Doing this, error message will be shown unless Search contains something different to Search...

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top