禁用回发的asp.net按钮单击 [英] Disable Postback on asp.net Button Click

查看:251
本文介绍了禁用回发的asp.net按钮单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上的一个按钮的onClick事件禁用回发。

我做了一些研究,并在网上大多数正在使用的OnClientClick和使用JavaScript。有没有办法来调用一个asp.net函数btnCommit_Click关于onClick的,而不是使用的OnClientClick和使用JavaScript的?

如果不是,我怎么会是能够把一个asp.net功能的JavaScript?

 < ASP:按钮的ID =btnCommit=服务器文本=保存的TabIndex =5
    的onclick =btnCommit_Click/>

更新时间:
我有一个包含复选框的GridView,一旦用户进行修改,并点击了保存按钮回发时,我松我就在想禁用按钮的onclick事件回发的复选框所做的所有选择将解决这个问题...


解决方案

  

我有一个包含复选框的GridView,一旦用户使他们的
  改变并点击了保存按钮回发时,我松
  对复选框所做的所有选择


您必须保持的Page_Load Page.IsPostback 是价值假像下面时..

 保护无效的Page_Load(对象发件人,EventArgs的发送)
{
    如果(!Page.IsPostBack)
    {
        //你的code
    }
}

这不会造成松动您点击按钮后做出格复选框选择。


的GridView的EnableViewState必须为True


您模板字段必须在设计师页

I would like to disable postback on a onClick event of a button.

I did some research online and most are using onClientClick and using javascript. Is there a way to call a asp.net function "btnCommit_Click" on the onClick instead of using onclientclick and using javascript?

If not, how would I be able to incorporate a asp.net function with javascript?

<asp:Button ID="btnCommit" runat="server" Text="Save" TabIndex="5" 
    onclick="btnCommit_Click" />

UPDATED I have a GridView which contains checkboxes, once the user makes their changes and click on a "Save Button" a Post Back occurs and I loose all the selections made to the checkboxes I was thinking of disabling the postback on the OnClick Event of the button would solve that issue...

解决方案

I have a GridView which contains checkboxes, once the user makes their changes and click on a "Save Button" a Post Back occurs and I loose all the selections made to the checkboxes

You have to keep the Page_Load under Page.IsPostback during is's value to false like below..

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        //Your code
    }
}

This will not cause to loose you grid checkbox selection made after clicking the button.


Your GridView EnableViewState must be True


Your template fields must be in designer page

这篇关于禁用回发的asp.net按钮单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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