的OnClientClick onClick为不同时工作的? [英] OnclientClick and OnClick is not working at the same time?

查看:129
本文介绍了的OnClientClick onClick为不同时工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似下面的按钮,

<asp:Button ID="pagerLeftButton" runat="server" OnClientClick="disable(this)" onclick="pager_Left_Click" Text="<" />

当我用我的按钮那样,的onclick不点火。当我删除的OnClientClick,那么的onclick被解雇。

When I use my button like that, onclick is not firing. When I remove OnClientClick, then onclick is firing.

我需要做的是,在回发期间禁用按钮,使它的回传结束后,有什么。

What I need to do is, disable the button during the postback and enable it after the postback ends.

编辑:附加信息:

我添加了破发点,以我的射击功能是C#的一部分,我调试,他们没有射击是肯定的。这些功能都像

I added break point to my firing functions is c# part and I am debugging, they are not firing for sure. Those functions are like

protected void pager_Left_Click(object sender, EventArgs e)
{
//Do smthing.
}
protected void pager_Right_Click(object sender, EventArgs e)
{
//Do smthing.
}

当我点击我的按钮,它是1-2秒禁用自动启用,但为什么它被启用,我不知道。我没加任何一部分,它被再次启用。

and when I click my button, it is disabled for 1-2 seconds and automatically enabled, but I am not sure why it is enabled. I didn't add any part for it to be enabled again.

推荐答案

从<一个href=\"http://encosia.com/disable-a-button-control-during-postback/\">http://encosia.com/disable-a-button-control-during-postback/:

诀窍是使用按钮控制的OnClientClick和UseSubmitBehavior属性。还有其他的方法,在服务器端添加属性,涉及code,但我认为这样做的简单性是更吸引人的:

The trick is to use the OnClientClick and UseSubmitBehavior properties of the button control. There are other methods, involving code on the server side to add attributes, but I think the simplicity of doing it this way is much more attractive:

<asp:Button runat="server" ID="BtnSubmit"  OnClientClick="this.disabled = true; this.value = 'Submitting...';"   UseSubmitBehavior="false"  OnClick="BtnSubmit_Click"  Text="Submit Me!" />


  
  

的OnClientClick允许您添加客户端onclick脚本。在这种情况下中,JavaScript将禁用按钮元素及其文本值更改为进度消息。当回发完成后,新生成的页面将恢复按钮回其初始状态,没有任何额外的工作。

OnClientClick allows you to add client side OnClick script. In this case, the JavaScript will disable the button element and change its text value to a progress message. When the postback completes, the newly rendered page will revert the button back its initial state without any additional work.

这是带有禁用客户端上的一个提交按钮的一个缺陷是,它会取消该浏览器的提交,因此,回发。在UseSubmitBehavior属性设置为false告诉.NET注入必要的客户端脚本反正火回传,而不是依赖于浏览器的表单提交行为。在此情况下,code将其注入将是:

The one pitfall that comes with disabling a submit button on the client side is that it will cancel the browser’s submit, and thus the postback. Setting the UseSubmitBehavior property to false tells .NET to inject the necessary client script to fire the postback anyway, instead of relying on the browser’s form submission behavior. In this case, the code it injects would be:

__doPostBack('BtnSubmit','')

这是添加到我们的OnClientClick code的结束,给我们这个呈现的HTML:

This is added to the end of our OnClientClick code, giving us this rendered HTML:

<input type="button" name="BtnSubmit"  onclick="this.disabled = true; this.value ='Submitting...';__doPostBack('BtnSubmit','')"  value="Submit Me!" id="BtnSubmit" />

这给出了一个漂亮的按钮禁用效果和处理文本,而回发完成。

This gives a nice button disable effect and processing text, while the postback completes.

这篇关于的OnClientClick onClick为不同时工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆