使用按钮作为执行javascript的链接会阻止OnClick工作

Using button as link that executes javascript prevents OnClick from working

本文关键字:链接 工作 OnClick javascript 按钮 执行      更新时间:2023-09-26

我使用按钮作为链接,因为当按下按钮时,它会使用Javascript打开In-Line HTML的弹出窗口(http://www.enthropia.com/labs/ibox/):

<a href="#inner_content" rel="ibox&width=800&height=400" title="Search Non Scrum Stories"><asp:Button ID="searchButton" runat="server" Text="Search Stories" OnClick="searchButton_Click" /></a>

但是,当我按下按钮时,这会阻止OnClick C#的执行。我该如何解决这个问题?

我建议您使用此代码

<a href="#inner_content" rel="ibox&width=800&height=400" title="Search Non Scrum Stories">
</a>
<asp:Button ID="searchButton" runat="server" Text="Search Stories" OnClick="searchButton_Click" />

大卫,你必须分开html链接和按钮(它不是xaml)

或者,您可以使用LinkButton-http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.aspx

示例(来自链接文档):

<asp:LinkButton id="LinkButton1" 
       Text="Click Me" 
       Font-Names="Verdana" 
       Font-Size="14pt" 
       OnClick="LinkButton_Click" 
       runat="server"/>

将标签分开,并将您的按钮作为提交按钮放入,或者您可以执行以下操作:

<form action="ur_popup_page" onsumit="javascriptsunction()">
<asp:Button type="submit" id="searchbutton"/>
</form>