ImageButton strange action
I've added 2 image buttons in my master page. Their purpose is to change the language of the site.
<div id="SiteHeader">
<asp:ImageButton ID="imgBtnBulgarian" runat="server" ImageUrl="~/App_Themes/Default/images/bg flag.png" AlternateText="Bulgarian" OnClick="imgBtnBulgarian_Click" ValidationGroup="language" />
<asp:ImageButton ID="imgBtnEnglish" runat="server" ImageUrl="~/App_Themes/Default/images/english flag.png" AlternateText="English" OnClick="imgBtnEnglish_Click" ValidationGroup="language" />
</div>
This is the code behind
protected void imgBtnEnglish_Click(object sender, EventArgs e)
{
Session["language"] = "en-GB";
Response.Redirect(Request.Url.AbsoluteUri);
}
protected void imgBtnBulgarian_Click(object sender, EventArgs e)
{
Session["language"] = "bg-BG";
Response.Redirect(Request.Url.AbsoluteUri);
}
They work just f开发者_运维知识库ine. The problem occur when I have some form in my Content Place Holder. For example login form. When I enter the data in the textboxes and press enter instead of clicking the login button it clicks one of the ImageButtons. When I click the login button with the mouse, it works fine. Can you help me solve this problem?
One solution is, that you put your login controls in a asp:Panel and set the DefaultButton property to your login button.
Pseudocode:
<asp:Panel runat=server DefaultButton=btnLogin>
Account: <asp:TextBox id=txtAccount ... />
Password: <asp:TextBox id=txtAccount ... />
<asp:Button id=btnLogin runat=server Text=Login ... />
</asp:Panel>
精彩评论