Google Search on asp page disables other buttons.

Last post 05-25-2009 1:35 AM by aditya1986. 3 replies.

Sort Posts:

  • Google Search on asp page disables other buttons.

    05-24-2009, 5:40 PM
    • Member
      point Member
    • oasisfleeting
    • Member since 05-11-2009, 10:43 PM
    • Posts 1

    When I attempt to place a google search on my asp.net page the other buttons onclick events do not fire..

     Here is my code.

    <div class="googleSearchBox" style="margin-left:150px">

    Search by Keyword:

    <asp:TextBox ID="qu" MaxLength="512" Width="250px" AutoPostBack="false" runat="server" />

    <asp:ImageButton ID="googlesearch" Text="Gun Show Search"

    OnClick="googlesearch_Click" runat="server" />

    <asp:RequiredFieldValidator ID="_rfvQ" ControlToValidate="qu" runat="server" />

    <asp:HiddenField ID="cx" Value="008038850013659563853:gbg7oenu7bs" runat="server" />

    <asp:HiddenField ID="cof" Value="FORID:10" runat="server" />

    </div>

    <br />

    <script type="text/javascript">

    function checkKey() {

    if (window.event.keyCode == 13) // checks whether the ENTER key

    // is pressed

    {

    window.event.cancelBubble =
    true;

    window.event.returnValue = false;

    var btnName = "_btnSearch";

    var btn = document.getElementById(btnName);

    if (btn) btn.click();

    }

    }

      

    1    protected void googlesearch_Click(Object sender, EventArgs e)
    2        {
    3            if (!IsValid)
    4                return;
    5    
    6            Response.Redirect(
    7                String.Format(
    8                    "http://www.google.com/cse?q={0}&cx={1}&cof={2}",
    9                    HttpUtility.UrlEncode(SanitizeUserInput(qu.Text.Trim())),
    10                   HttpUtility.UrlEncode(cx.Value),
    11                   HttpUtility.UrlEncode(cof.Value)
    12                   ),
    13               false
    14               );
    15   
    16           Context.ApplicationInstance.CompleteRequest();
    17       }
    
     
    Filed under: , ,
  • Re: Google Search on asp page disables other buttons.

    05-25-2009, 1:24 AM
    • Contributor
      6,273 point Contributor
    • anzer
    • Member since 10-19-2004, 4:00 AM
    • UAE
    • Posts 1,265

     From your code what I can understand is the RequiredFieldValidator is making the issue.. The validator will work for all the button unless you specidfied ValidationGroup property for the controls you need to validate.

    So to make your code work correctly just add a common validationgroup to the google search textbox, button and validation control.

    <asp:TextBox ID="qu" MaxLength="512" Width="250px" AutoPostBack="false" runat="server"
    ValidationGroup="g" />

    <asp:ImageButton ID="googlesearch" Text="Gun Show Search" ValidationGroup="g"
    OnClick="googlesearch_Click" runat="server" />

    <asp:RequiredFieldValidator ID="_rfvQ" ControlToValidate="qu" runat="server" ValidationGroup="g"  />

    If this post was useful to you, please mark it as answer.

    ClientSideAsp.Net | Blog
  • Re: Google Search on asp page disables other buttons.

    05-25-2009, 1:27 AM
    Answer
    • Contributor
      6,273 point Contributor
    • anzer
    • Member since 10-19-2004, 4:00 AM
    • UAE
    • Posts 1,265

     Alternatively you can just disable the validation of other buttons by simply setting CausesValidation="false" .

    Sample code

    <asp:Button ID="btnOtherButton" Text="Save" runat="server" CausesValidation="false" OnClick="btnSave_Click" />

    If this post was useful to you, please mark it as answer.

    ClientSideAsp.Net | Blog
  • Re: Google Search on asp page disables other buttons.

    05-25-2009, 1:35 AM
    • Contributor
      3,230 point Contributor
    • aditya1986
    • Member since 05-04-2009, 1:04 AM
    • Posts 529

     you mention validation group="somename" for both requried field validator and for the button

    and you also write a line of code as i mentioned 

    protected void googlesearch_Click(Object sender, EventArgs e)
    {
    if (Page.IsValid)
    {

    your code

    }
    }

    i hopes it helps you
    MARK AS ANSWER if post helps
Page 1 of 1 (4 items)