Cannot make master page button click default button

mugsey used Ask the Experts™
I cannot get a search button to fire using the enter key as oppose to clicking the button on a master page.

Here I have the button set as default in the master page form

<form id="form1" runat="server" defaultbutton="_searchButton">

Then in the master page here is the button and search textbox

  <div id="search">
                    <div class='searchbox'>
                            <asp:TextBox ID="_searchTextBox" runat="server" CssClass="input2" AutoPostBack="true">Search for activity</asp:TextBox>
                        <asp:ImageButton ID="_searchButton" runat="server" CssClass="submit" ImageUrl="images/search_btn.gif"
                            OnClick="_searchButton_Click" AltText="Search"  />

In the code behind master page I set the default button on page load

this.form1.DefaultButton = _searchButton.UniqueID;

Then in each page load

In each page on page load I attempt to set the default button

        HtmlForm mainform = (HtmlForm)Master.FindControl("form1");
        mainform.DefaultButton = mainform.FindControl("_searchButton").UniqueID;  

However the search button is not being fireed


Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
If I correctly understand what you are trying to do, you may want to try using

<form id="form1" runat="server" defaultbutton="_searchButton" onSubmit="_searchButton_Click">

instead of the onClick in the submit button. onClick is for mouse clicks, onsubmit will trigger regardless of how the form was submitted (enter key, mouse click).
protected void Page_Load(object sender, EventArgs e)
        Page.Master.Page.Form.DefaultButton = Button.UniqueID;


ok thanks

I have a default.aspx page (derived from masterpage)   with a search button and I want to make that the default.
on the default.aspx page do this:
protected void Page_Load(object sender, EventArgs e)
       this.Master.Page.Form.DefaultButton = Button1.UniqueID;

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial