Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6576847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:33:45+00:00 2026-05-25T15:33:45+00:00

I have a textbox onin a masterpage which I’m using as a search box.

  • 0

I have a textbox onin a masterpage which I’m using as a search box. When the user presses enter I want to redirect to an other page with the search terms in the url paramaters.

Trouble it only seems to work on pages that don’t have their own page_load subs.

            <div id="search-bar">
                <asp:TextBox ID="txtSearch" runat="server" Text=""></asp:TextBox>
                <asp:Button ID="btnSearch" runat="server" style="display:none"/>
            </div>

IN masterpage page_load:

    txtSearch.Attributes.Add("onKeyDown", "do_search(this)")

javascript function so that when user presses enter it calls btnSearch_Click

    function do_search() {
        if (event.keyCode == 13) {
            var invisibleButton = document.getElementById('<%=btnSearch.ClientID %>');
            __doPostBack(invisibleButton.name, '');
        }
    }


Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
    If Trim(txtSearch.Text) <> "" Then
        Response.Redirect("viewall.aspx?q=" & txtSearch.Text, True)
    End If
End Sub

It only works on pages that don’t have a Page_load i.e. the response.redirect doesn’t fire on pages with a page_load.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:33:47+00:00Added an answer on May 25, 2026 at 3:33 pm

    Ok, thanks for the answers above but didn’t seem to work. I finally got around this via this article…it seems a mysterious problem and is browser related.

    http://www.pcreview.co.uk/forums/response-redirect-not-working-pressing-enter-key-t2888253.html

    3rd post down:

    “I then tried wrapping the controls in a
    Panel and set the Panel’s DefaultButton and that seemed to get it
    working in IE.”

    My page now is as follows:

                    <asp:Panel ID="Panel1" runat="server" DefaultButton="btnSearch">
                        <asp:TextBox ID="txtSearch" runat="server" Text=""></asp:TextBox>
                        <asp:Button ID="btnSearch" runat="server" Style="display: none" />
                    </asp:Panel>
    

    …and it works! finally.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have image button for browse and upload I have textbox using
I am creating intellisense as Java's intellisense at C#.I have TextBox which user can
I am using C#.Net. I have textbox which allow only number, decimal and percentage(%)
I have a textbox with default text like Enter Name Once user starts typing
I have textbox to enter only alphabet and numerical values. I do not want
I have a textbox which I have added an attribute to using the following
I have a textbox, and everytime the user presses a key, I compute the
I have TextBox (multiline) and Label in an UpdatePanel which I refresh with javascript
I have a textbox whose input is being handled by jQuery. $('input.Search').bind(keyup, updateSearchTextbox); When
I have textbox that I want to run some jquery when the textbox loses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.