Cannot make master page button click default button

mugsey
mugsey used Ask the Experts™
on
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'>
                        <label>
                            <asp:TextBox ID="_searchTextBox" runat="server" CssClass="input2" AutoPostBack="true">Search for activity</asp:TextBox>
                        </label>
                        <asp:ImageButton ID="_searchButton" runat="server" CssClass="submit" ImageUrl="images/search_btn.gif"
                            OnClick="_searchButton_Click" AltText="Search"  />
                    </div>
                </div>

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

 




Comment
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).
Commented:
protected void Page_Load(object sender, EventArgs e)
    {
        Page.Master.Page.Form.DefaultButton = Button.UniqueID;
    }

Author

Commented:
ok thanks

I have a default.aspx page (derived from masterpage)   with a search button and I want to make that the default.
Commented:
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