English 中文(简体)
弃置一个纽子,防止向服务器点击事件
原标题:Disabling a button prevents click event to server

I have a repeater with a button in that saves some data to the DB. My issue is sometime the call down to the DB takes a little bit and the user sometimes will click save a few times causing multiple entries to be added to the db. So my first thought was to add a throbber and disable the button when its clicked. The throbber is spinning away but when the button is disabled it prevents the call to the server. So I looked at this but since I have a bunch of different buttons (Update, Add, ...) that there are a few different server side methods being called so I can t just post __doPostBack($(button).attr( id ), ). So i was thinking that I might need to do a ajax call but I wanted to see if there was any other ideas. Here s my code: The onClientClick is actually being setup on the server side but this is basically whats being done.

<>Repeater

<div style="position: relative; float: left;">
      <asp:Button ID="btnSave" runat="server" Text="Assign" OnClientClick="return fnAssignedButtonPressed(this);", OnClick="btnSave_Click" />
</div>

www.un.org/Depts/DGACM/index_spanish.htm

function fnAssignedButtonPressed(button) {
//validating inputs
var valid = true;

        if(valid)
        {
           $(button).attr( disabled ,  disabled );
           showWaitCursor(true);
           __doPostBack($(button).attr( id ),  );
        }
  return valid;
}

<>Serverside:

protected void btnSave_Click(object sender, EventArgs e)
{
 //save
 // This method doesn t call called when I disable the button!!
}
问题回答

最后,我不知道我如何看待这一问题。

function fnAssignedButtonPressed(button) 
{ 
//validating inputs 
var valid = true;
     if(valid)
     {
       showWaitCursor(true);
       //set a timeout and then disable the button, this prevents the user from click the button multiple times.
       // need the timeout bc when the button becomes disabled it prevents the onlick event from firing.
       setTimeout(function() {fnDisableButton(button)}, 1); 
    }
}

function fnDisableButton(button)
{
    $(button).attr( disabled ,  disabled );
}

根据您的设想,Ajax无疑是一个很好的选择。 否则,你就可展示使用jquery s UI dialog的等待模式,例如:

$( <div class="dialog" title="Please Wait">Please wait while your request is processing</div> ).dialog({
    modal: true,
    width: 350,
    open: function (event, ui) {
        $(".ui-dialog-titlebar-close").hide();
    },
});

服务器一旦返回,该模式就应当自动消失,而国际宇宙航行联合会的示范方案则gra弃了屏幕,因此用户不能点击任何东西。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签