Question : Cannot make master page button click default button

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

 




Answer : Cannot make master page button click default button

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).
Random Solutions  
 
programming4us programming4us