65.9K
CodeProject is changing. Read more.
Home

How to do a click once button in AJAX

starIconstarIconemptyStarIconemptyStarIconemptyStarIcon

2.00/5 (4 votes)

Feb 7, 2008

CPOL
viewsIcon

21831

A click once button.

Introduction

This code makes a button clickable only once.

Background

I did a page with an UpdatePanel on it.

Since I had a lot of controls between the order button (BESTÄLL) and the panel, I did the order button external to the panel.

I needed the order button clickable only once, in order to achieve this:

Two.JPG

Using the Code

I added an onSubmit method to the form:

<form id="form1" runat="server" 
  onsubmit="document.form1.btnOrder.disabled = true;return true;"> 
...
<button id="btnOrder" style="MARGIN-LEFT: 20%" 
  runat="server" text="BESTÄLL"></button>

Points of Interest

The key to make it work is:

return true;

Otherwise, the server side event doesn't trigger.

Comments

I would appreciate feedback and tips on a more .NET-tish way of doing this.