On my site, I have a search function on the main page (the default value is not set there, also not on the form). I have a login on the content page, there I use the asp panel with the default button. but when I press the enter button in the login text box, my site continues to work with the search event handler ... What could be the reason?
Some codes:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(Button1.Text);
}
<asp:Panel ID="pnl1" runat="server" DefaultButton="Button1">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:LinkButton ID="Button1" runat="server" Text="Button1" OnClick="Button1_Click" />
</asp:Panel>
protected void btnSearch_Click(object sender, EventArgs e)
{
if (!txtSearch.Text.Equals(""))
{
Response.Redirect("searchresults.aspx?search=" + txtSearch.Text);
}
}
<div id="searchbar">
<asp:TextBox ID="txtSearch" CssClass="searchbar-field" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" CssClass="searchbar-btn" runat="server" Text="Zoek" OnClick="btnSearch_Click" />
</div>
OK found a solution: it is required to use Button, but not LinkButton. Then it should be good ...
Ozkan source
share