Note that there are some explanatory texts on larger screens.

plurals
  1. POSearch Text Box on Master Page fires off validation error
    primarykey
    data
    text
    <p>I came across an interesting problem recently. In an ASP.NET Master Page, I have a Login Control and a Google Search Box as shown below:</p> <pre><code> &lt;div id="searchBox"&gt; &lt;table border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tr&gt;&lt;td&gt; &lt;asp:TextBox ID="q" MaxLength="100" AutoPostBack="false" runat="server" onclick="ctl00$q.value=''" CausesValidation="False" Text="Google Custom Search" /&gt;&lt;/td&gt; &lt;td align="right"&gt; &lt;asp:ImageButton ID="_btnSearch" runat="server" AlternateText="Search" validationgroup="SearchGroup" CommandName="Search" ImageUrl="~/images/search.gif" OnClick="_btnSearch_Click"/&gt; &lt;/td&gt; &lt;td width="5px" align="right"&gt; &lt;asp:RequiredFieldValidator ID="_rfvQ" ControlToValidate="q" runat="server" validationgroup="SearchGroup" /&gt; &lt;asp:HiddenField ID="cx" Value="00054535354544538:kmy_69vgpnm" runat="server" /&gt; &lt;asp:HiddenField ID="cof" Value="FORID:11" runat="server" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; </code></pre> <p>Login Control</p> <pre><code>&lt;asp:LoginView ID="LoginView1" runat="server"&gt; &lt;AnonymousTemplate&gt; &lt;asp:Login ID="Login" runat="server" Width="100%" FailureAction="RedirectToLoginPage" meta:resourcekey="LoginResource1"&gt; &lt;LayoutTemplate&gt; &lt;table border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tr&gt; &lt;td width="60px"&gt;&lt;asp:Label runat="server" ID="lblUserName" AssociatedControlID="UserName" Text="Username:" meta:resourcekey="lblUserNameResource1" /&gt;&lt;/td&gt; &lt;td&gt;&lt;asp:TextBox id="UserName" runat="server" Width="95%" meta:resourcekey="UserNameResource2" /&gt;&lt;/td&gt; &lt;td width="5px" align="right"&gt; &lt;asp:RequiredFieldValidator ID="valRequireUserName" runat="server" SetFocusOnError="True" ControlToValidate="UserName" Text="*" ValidationGroup="Login" meta:resourcekey="valRequireUserNameResource1" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="height: 24px"&gt;&lt;asp:Label runat="server" ID="lblPassword" AssociatedControlID="Password" Text="Password:" meta:resourcekey="lblPasswordResource1" /&gt;&lt;/td&gt; &lt;td style="height: 24px"&gt;&lt;asp:TextBox ID="Password" runat="server" TextMode="Password" Width="95%" meta:resourcekey="PasswordResource2" /&gt;&lt;/td&gt; &lt;td width="5px" align="right" style="height: 24px"&gt; &lt;asp:RequiredFieldValidator ID="valRequirePassword" runat="server" SetFocusOnError="True" ControlToValidate="Password" Text="*" ValidationGroup="Login" meta:resourcekey="valRequirePasswordResource1" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;table border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tr&gt; &lt;td&gt;&lt;asp:CheckBox ID="RememberMe" runat="server" Text="Remember me" meta:resourcekey="RememberMeResource1"&gt;&lt;/asp:CheckBox&gt;&lt;/td&gt; &lt;td align="right"&gt; &lt;asp:ImageButton ID="Submit" runat="server" AlternateText="Login" CommandName="Login" ImageUrl="~/images/go.gif" ValidationGroup="Login" meta:resourcekey="SubmitResource1" /&gt; &lt;/td&gt; &lt;td width="5px" align="right"&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;div style="border-top: solid 1px black; margin-top: 2px; padding-top: 2px"&gt; &lt;br /&gt; &lt;asp:HyperLink ID="lnkRegister" runat="server" NavigateUrl="~/Register.aspx" meta:resourcekey="lnkRegisterResource1" ForeColor="#104A9D" Text="Create new account"&gt;&lt;/asp:HyperLink&gt;&lt;br /&gt; &lt;asp:HyperLink ID="lnkPasswordRecovery" runat="server" NavigateUrl="~/PasswordRecovery.aspx" meta:resourcekey="lnkPasswordRecoveryResource1" ForeColor="#104A9D" Text="I forgot my password"&gt;&lt;/asp:HyperLink&gt; &lt;/div&gt; &lt;/LayoutTemplate&gt; &lt;/asp:Login&gt; &lt;/AnonymousTemplate&gt; &lt;LoggedInTemplate&gt; &lt;div id="welcomebox"&gt; &lt;asp:LoginName ID="LoginName1" runat="server" FormatString="Hello {0}" meta:resourcekey="LoginName1Resource1" /&gt;&lt;br /&gt; &lt;small&gt; &lt;asp:HyperLink ID="lnkProfile" runat="server" Text="Edit Profile" NavigateUrl="~/EditProfile.aspx" meta:resourcekey="lnkProfileResource1" /&gt;&lt;br /&gt; &lt;asp:LoginStatus ID="LoginStatus1" Runat="server" meta:resourcekey="LoginStatus1Resource1" /&gt; &lt;/small&gt; &lt;/div&gt; &lt;/LoggedInTemplate&gt; &lt;/asp:LoginView&gt; </code></pre> <p>The search works fine if the user enters the text in the search text box and clicks the Search Button. However if the user enters the text in the search text box and hits the Enter button, then the validation for the Login control fires off. I want to avoid this since the user just wants to search.</p> <p>How do I prevent the validation from firing when the user hits enter in the search text box.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload