1
<asp:Button 
         ID="btnUpdate" 
         runat="server" 
         OnClick="btnUpdate_Click" 
         Text="Update" 
         CssClass ="btn" 
         ToolTip="Update" 
         Width="58px" />

`This is my code for button, want to use javascript..help plz

KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
Anboo
  • 103
  • 2
  • 17

2 Answers2

0

You should do it clientside, using javascript and not using C# code. Try to Add OnClientClick event on the button and disable it on the event.

Ghyath Serhal
  • 7,466
  • 6
  • 44
  • 60
  • – Anboo Oct 20 '11 at 05:29
  • @Ghylath - setting is to Disabled - ASP.Net for whatever reason doesn't post back properly. Need to use another technique – Jason Jong Oct 20 '11 at 05:33
0

Very easy to do to prevent the user pressing it twice - here is an example of using JavaScript to hide the button.

<asp:Button ID="btnUpdate" runat="server" OnClick="btnUpdate_Click" 
 OnClientClick="this.style.visibility = 'hidden';"
 Text="Update" CssClass ="btn" ToolTip="Update" Width="58px" />
Jason Jong
  • 4,310
  • 2
  • 25
  • 33
  • i have used this script but its not working – Anboo Oct 20 '11 at 05:36
  • i want to know whether server side onclick and client side onclick getting clash.. – Anboo Oct 20 '11 at 05:38
  • @Anboo - no, that piece of code wont clash. It will run the Client Side Code, ie you can do some confirmation. If the return is true, it will then post to the server. Are you using jQuery ? Makes it alot easier – Jason Jong Oct 20 '11 at 05:41
  • $('#buttonId').click(function() { $(this).attr('disabled', 'disabled'); }); I found this code..how to use this with asp button. – Anboo Oct 20 '11 at 05:48
  • @Anboo - thats using jQuery ... refer to this http://weblogs.asp.net/jeffwids/archive/2009/10/06/how-to-disable-an-asp-net-button-when-clicked.aspx Add in your code-behind `MyButton.Attributes.Add("onclick", "this.disabled=true;" + Page.ClientScript.GetPostBackEventReference(MyButton, "").ToString());` – Jason Jong Oct 20 '11 at 06:04