禁用回发的&LT; ASP:LinkButton的&GT; [英] Disable the postback on an <ASP:LinkButton>
问题描述
我有我的窗体上的ASP.NET LinkButton控件。我想用它为JavaScript在客户端和prevent它可以发布到服务器。 (我想用LinkButton控件,所以我可以其外观,在某些情况下,禁用它,所以直线上升的标签是不是preferred)。
I have an ASP.NET linkbutton control on my form. I would like to use it for javascript on the client side and prevent it from posting back to the server. (I'd like to use the linkbutton control so I can skin it and disable it in some cases, so a straight up tag is not preferred).
如何可以发布到服务器做我prevent呢?
How do I prevent it from posting back to the server?
推荐答案
ASPX code:
ASPX code:
<asp:LinkButton ID="someID" runat="server" Text="clicky"></asp:LinkButton>
背后code:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
someID.Attributes.Add("onClick", "return false;");
}
}
什么渲染为HTML是:
What renders as HTML is:
<a onclick="return false;" id="someID" href="javascript:__doPostBack('someID','')">clicky</a>
在这种情况下,会发生什么是的onclick功能成为你的验证。如果是假的,HREF链接不执行;但是,如果这是真的在href将得到执行。这消除了您的文章了。
In this case, what happens is the onclick functionality becomes your validator. If it is false, the "href" link is not executed; however, if it is true the href will get executed. This eliminates your post back.
这篇关于禁用回发的&LT; ASP:LinkButton的&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!