Click here to Skip to main content
16,017,857 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi all,
Please see the following code


XML
<body>
    <form id="form1" runat="server">
    <asp:Panel ID="Panel1" runat="server" Width="100" Height="300" BorderColor="Black"
        BorderWidth="1">
        <asp:ImageButton ID="ImageButton1" runat="server" AlternateText="Back" OnClientClick="alert('back button');"/>
    </asp:Panel>
    <br>
    <asp:Panel ID="Panel2" runat="server" Width="100" Height="300" BorderColor="Black" DefaultButton="Button2"
        BorderWidth="1">
        <asp:Button ID="Button2" runat="server" Text="submit" />
    </asp:Panel>
    </form>
</body>




Click inside the first panel and pressing enter key, the click event of back button is firing. How to avoid it?
Posted

[EDIT]
Set the property DefaultButton="Button2" for panel1 so that Button2 fires.

May not be the better solution but Disabling the Enter key works but depends on your requirement. see here[^]

You can use Link button instead of the Image button

XML
<asp:LinkButton ID="lnkButton1" runat="server">
    <img src="imageurl" />
</asp:LinkButton>





[EDIT]
 
Share this answer
 
v2
Comments
salini8588 28-Feb-11 6:03am    
The question is to avoid that click event
m@dhu 28-Feb-11 6:34am    
Check my updated answer.
Please Replace Your button with this code

<asp:imagebutton id="ImageButton1" runat="server" alternatetext="Back" onclientclick="return call();" />

add a javascript function

function call ()
{
alert('back button');
return false ;
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900