Search text box on main page throws validation error

I recently ran into an interesting problem. On the ASP.NET master page, I have an input control and a google search box as shown below:

    <div id="searchBox">
         <table border="0" cellpadding="0" cellspacing="0" width="100%">
                        <tr><td> <asp:TextBox ID="q" MaxLength="100" AutoPostBack="false" runat="server" onclick="ctl00$q.value=''" CausesValidation="False" Text="Google Custom Search" /></td>
                           <td align="right">
                              <asp:ImageButton ID="_btnSearch" runat="server" AlternateText="Search" validationgroup="SearchGroup"
                                 CommandName="Search" ImageUrl="~/images/search.gif" OnClick="_btnSearch_Click"/>
                           </td>
                           <td width="5px" align="right">
                           <asp:RequiredFieldValidator ID="_rfvQ" ControlToValidate="q" runat="server" validationgroup="SearchGroup" />
<asp:HiddenField ID="cx" Value="00054535354544538:kmy_69vgpnm" runat="server" />
<asp:HiddenField ID="cof" Value="FORID:11" runat="server" /></td>
                        </tr>
                     </table>      
         </div>

      

Login control

<asp:LoginView ID="LoginView1" runat="server">
        <AnonymousTemplate>
           <asp:Login ID="Login" runat="server" Width="100%" FailureAction="RedirectToLoginPage" meta:resourcekey="LoginResource1">
              <LayoutTemplate>
                 <table border="0" cellpadding="0" cellspacing="0" width="100%">
                    <tr>
                       <td width="60px"><asp:Label runat="server" ID="lblUserName" AssociatedControlID="UserName" Text="Username:" meta:resourcekey="lblUserNameResource1" /></td>
                       <td><asp:TextBox id="UserName" runat="server" Width="95%" meta:resourcekey="UserNameResource2" /></td>
                       <td width="5px" align="right">
                          <asp:RequiredFieldValidator ID="valRequireUserName" runat="server" SetFocusOnError="True"
                             ControlToValidate="UserName" Text="*" ValidationGroup="Login" meta:resourcekey="valRequireUserNameResource1" />
                       </td>
                    </tr>
                    <tr>
                       <td style="height: 24px"><asp:Label runat="server" ID="lblPassword" AssociatedControlID="Password" Text="Password:" meta:resourcekey="lblPasswordResource1" /></td>
                       <td style="height: 24px"><asp:TextBox ID="Password" runat="server" TextMode="Password"  Width="95%" meta:resourcekey="PasswordResource2" /></td>
                       <td width="5px" align="right" style="height: 24px">
                          <asp:RequiredFieldValidator ID="valRequirePassword" runat="server" SetFocusOnError="True"
                             ControlToValidate="Password" Text="*" ValidationGroup="Login" meta:resourcekey="valRequirePasswordResource1" />
                       </td>
                    </tr>
                 </table>
                 <table border="0" cellpadding="0" cellspacing="0" width="100%">
                    <tr>
                       <td><asp:CheckBox ID="RememberMe" runat="server" Text="Remember me" meta:resourcekey="RememberMeResource1"></asp:CheckBox></td>
                       <td align="right">
                          <asp:ImageButton ID="Submit" runat="server" AlternateText="Login"
                             CommandName="Login" ImageUrl="~/images/go.gif" ValidationGroup="Login" meta:resourcekey="SubmitResource1" />
                       </td>
                       <td width="5px" align="right">&nbsp;</td>
                    </tr>
                 </table>
                 <div style="border-top: solid 1px black; margin-top: 2px; padding-top: 2px">
                    <br />
                    <asp:HyperLink ID="lnkRegister" runat="server" NavigateUrl="~/Register.aspx" meta:resourcekey="lnkRegisterResource1" ForeColor="#104A9D" Text="Create new account"></asp:HyperLink><br />
                    <asp:HyperLink ID="lnkPasswordRecovery" runat="server" NavigateUrl="~/PasswordRecovery.aspx" meta:resourcekey="lnkPasswordRecoveryResource1" ForeColor="#104A9D" Text="I forgot my password"></asp:HyperLink>
                 </div>
              </LayoutTemplate>
           </asp:Login>
        </AnonymousTemplate>
        <LoggedInTemplate>
           <div id="welcomebox">
              <asp:LoginName ID="LoginName1" runat="server" FormatString="Hello {0}" meta:resourcekey="LoginName1Resource1" /><br />
              <small>
              <asp:HyperLink ID="lnkProfile" runat="server" Text="Edit Profile" NavigateUrl="~/EditProfile.aspx" meta:resourcekey="lnkProfileResource1" /><br /> 
              <asp:LoginStatus ID="LoginStatus1" Runat="server" meta:resourcekey="LoginStatus1Resource1" />
              </small>
           </div>
        </LoggedInTemplate>
     </asp:LoginView>

      

The search works great if the user enters text into the search text box and clicks the search button. However, if the user enters text into the search text box and presses the "Enter" button, then the login validation check is triggered. I want to avoid this as the user just wants to search.

How to prevent disabling validation when a user enters a search text box.

Thanks.

0


a source to share


2 answers


You need to read ValidationGroups . You can also change the default button - link text



+4


a source


when i understand your problem ... i think ... if you only want to search on the input button of a given search as the default button and at the same time you want it to work and not trigger validation for the Login textbox, then set property of the search button CauseValidation = false. If it is your fault then you will work fine, otherwise you will detail your problem.



0


a source







All Articles