Question

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.

Was it helpful?

Solution

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...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top