使用C#在ASP.net中出现图像按钮OnClientClick()事件问题 [英] Image button OnClientClick() event issue in ASP.net using C#
问题描述
我有一个网页(第一个窗口).在该页面中,我有一个图像按钮,该按钮具有OnClientClick事件.在那种情况下,我将javascript方法称为 OpenHelpWindow()
,即
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()"
现在,每当我单击该图像按钮时,javascript方法(OpenHelpWindow())
中的事件就会触发,并会打开新帮助" Web窗口.它可以正常工作,但问题是,当我按Enter键时,该事件也会触发并向我显示帮助窗口.
现在我想停止第二个窗口(帮助"窗口),当按下输入键.
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.
如何解决此问题?
第一个Web窗口图像"按钮的我的代码"是
My Code for the first web window Image button is,
.
.
<asp:ImageButton ImageUrl="~/Images/help.png" runat="server" ID="ibtnHelp"
AlternateText="Help" ToolTip="Help" OnClientClick="OpenHelpWindow()" />
.
.
OpenHelpWindow()的Javascript代码是
function OpenHelpWindow()
{
var newWin = null;
try
{
newWin = window.open("../Common/OpenHelpUrl.aspx");
newWin.focus();
return false;
}
finally
{
newWin = null;
}
}
推荐答案
您的 ImageButton
是表单的默认按钮,这意味着当用户按下Enter键时,该按钮会自动被按下".这是标准的ASP.NET行为.
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.
您可以通过在< ImageButton .../>
标签中添加以下属性来更改此设置:
You can change this by adding the following attribute to your <ImageButton.../>
tag:
UseSubmitBehavior="False"
祝你好运!
编辑
如果这不起作用(应该这样做!),则可以通过在表单中添加一个不可见的虚拟按钮来欺骗浏览器:
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;"/>
,然后将 defaultButton ="dummy"
添加到您的< form/>
中.
and then adding defaultButton="dummy"
to your <form />
.
这篇关于使用C#在ASP.net中出现图像按钮OnClientClick()事件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!