Reputation: 53
I'm trying to run a web experiment that uses two-player interaction. In order to do that, it's crucial that double-clicking is not allowed. I use the the following code (C#, ASP.NET):
protected void decisionM2Button_Click(object sender, EventArgs e)
{
decisionM2Button.Enabled = false;
decisionM1Button.Enabled = false;
decisionP0Button.Enabled = false;
decisionP1Button.Enabled = false;
decisionP2Button.Enabled = false;
}
When I run the application on the local host the buttons are disabled fast enough to prevent any double clicking. On the server it's not fast enough, and when two-three button are clicked fast enough the whole application/experiment is stuck.
Is there any way to resolve this?
Thanks!
Upvotes: 0
Views: 296
Reputation: 63772
Solution on the client side is fast, but it can also be bypassed easily.
If you're interested in validity (which you obviously are, otherwise you'd just tell your players not to click twice, dammit! :) ), the best way would be to make sure only the first click counts. Depending on your application, a Session might be enough to do what you want - on first click, set a value in Session. Each of the buttons will check the Session first, and return immediately if the expected value is already there. You can then reset the session when it's appropriate.
Of course, there's plenty of other ways to store this kind of state, but I'd have to know more about what you're actually trying to do, and in what kind of environment.
Upvotes: 1
Reputation: 120
Apply ajax UpdateProgress and put your code in UpdatePanel as:
<aspAtlas:UpdateProgress ID="upUpdatePanelProgress" runat="server" DisplayAfter="0"
DynamicLayout="true" AssociatedUpdatePanelID="updpnlProgram">
<ProgressTemplate>
<asp:Panel ID="Panel1" CssClass="overlay" runat="server">
<img runat="server" id="img1" src="../Images/UpdateProgress.gif" alt="Loading..." /><br />
<br />
<b>Loading...</b>
</asp:Panel>
</ProgressTemplate>
</aspAtlas:UpdateProgress>
<aspAtlas:UpdatePanel runat="server" ID="updpnlProgram" UpdateMode="Conditional">
<ContentTemplate>
<div>
//--Your code in this div
</div>
</ContentTemplate>
<Triggers>
<aspAtlas:PostBackTrigger ControlID="decisionM2Button" />
</Triggers>
</aspAtlas:UpdatePanel>
Upvotes: 0
Reputation: 637
JavaScript / JQuery will be your choice IMO, though, client side can be modify by external tools, so consider that.
Upvotes: 0
Reputation: 4753
As soon as the click is made, intead of disabling it, try to assign a CSS class which will hide it..this might be fast enough..
You can set css to your button dynamically as follows:
button.css="cssClassname";
the other thing that you can do by dynamic java script.. call a javscript function and disable it from client side rather than from server side..
hope this helps..
Upvotes: 0