javascript - Image button OnClientClick() event issue in ASP.net using C# - Stack Overflow

I am having one Web page(First window). In that page I am having one image button, Which is having OnCl

I am having one Web page(First window). In that page I am having one image button, Which is having OnClientClick event. In that event I call a javascript method as OpenHelpWindow() i.e.

OnClientClick ="OpenHelpWindow()"

Now whenever I clicked that image button the event in the javascript method(OpenHelpWindow()) will get trigger and it will open the New help web window. Its working properly but the problem is, When I press Enter key then also the event will get fire and show me the help window.

Now I want to stop the second window (Help window) opening when the Enter key pressed.

How can I resolve this problem?

My Code for the first web window Image button is,

.aspx code

.
.
<asp:ImageButton ImageUrl="~/Images/help.png" runat="server" ID="ibtnHelp"
                                AlternateText="Help" ToolTip="Help"  OnClientClick="OpenHelpWindow()" />
.
.

Javascript code for OpenHelpWindow() is

function OpenHelpWindow()
{
var newWin = null;
try
 {
    newWin = window.open("../Common/OpenHelpUrl.aspx");
    newWin.focus();
    return false;
 }
finally
 {
    newWin = null;
 }
}

I am having one Web page(First window). In that page I am having one image button, Which is having OnClientClick event. In that event I call a javascript method as OpenHelpWindow() i.e.

OnClientClick ="OpenHelpWindow()"

Now whenever I clicked that image button the event in the javascript method(OpenHelpWindow()) will get trigger and it will open the New help web window. Its working properly but the problem is, When I press Enter key then also the event will get fire and show me the help window.

Now I want to stop the second window (Help window) opening when the Enter key pressed.

How can I resolve this problem?

My Code for the first web window Image button is,

.aspx code

.
.
<asp:ImageButton ImageUrl="~/Images/help.png" runat="server" ID="ibtnHelp"
                                AlternateText="Help" ToolTip="Help"  OnClientClick="OpenHelpWindow()" />
.
.

Javascript code for OpenHelpWindow() is

function OpenHelpWindow()
{
var newWin = null;
try
 {
    newWin = window.open("../Common/OpenHelpUrl.aspx");
    newWin.focus();
    return false;
 }
finally
 {
    newWin = null;
 }
}
Share Improve this question edited Jan 9, 2013 at 10:50 SuryaKavitha asked Jan 9, 2013 at 10:08 SuryaKavithaSuryaKavitha 5235 gold badges21 silver badges38 bronze badges 3
  • is this your default button? – Prasad Commented Jan 9, 2013 at 10:10
  • @Prasad: Default button means, What do u mean? – SuryaKavitha Commented Jan 9, 2013 at 10:20
  • see below ans of Roy Dictus!!! – Prasad Commented Jan 9, 2013 at 10:22
Add a ment  | 

2 Answers 2

Reset to default 4

Your ImageButton is the form's default button, which means that when the user presses Enter, that button automagically gets "pressed". This is standard ASP.NET behavior.

You can change this by adding the following attribute to your <ImageButton.../> tag:

UseSubmitBehavior="False"

Good luck!

EDIT

If this doesn't work (which it should!), then you can fool the browser by adding an invisible dummy button in your form:

<asp:Button ID="dummy" runat="server" Text="" OnClientClick="return false;" style="display:none;"/>

and then adding defaultButton="dummy" to your <form />.

Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744244858a4564876.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信