|
-
Apr 13th, 2004, 08:55 AM
#1
Thread Starter
Frenzied Member
Disabling Submit Button
I'd like to disable a submit button to prevent mutiple database entries.
I've not had a problem disabling the button using Javascript but the method i used seems to intercept the postback and so the normal code is never executed. I found out i had to manually post the form, with this the form is submitted and page_load runs but i still can't get the button_onclick event to run after the button is disabled. code.....
VB Code:
'In code behind
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
btnSubmit.Attributes.Add("onclick", "return disableMe(this);")
End If
End Sub
Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmit.Click
'Fairly long process here
End Sub
'In Script in .aspx file
<script language="javascript">
function disableMe(btn) {
btn.disabled = true;
document.form1.submit();
return true;
}
</script>
I've found quite a few examples on the web but couldn't get any of them to work.
any ideas?
-
Apr 15th, 2004, 09:14 AM
#2
Thread Starter
Frenzied Member
anyone? I'd really like to get this working if at all possible.
-
Apr 16th, 2004, 10:06 PM
#3
I wonder how many charact
So you just want to disable a Submit button after it has been pressed (sent back to the server)?
Then in your code behind, just set the SubmitButton.Enabled property to false in your click_event.
Then you don't need the javascript.
But, as far as the Javascript, instead of
Code:
document.form.submit
you have to something like this I forget what x is though.. I think its the id of the control that raised the postback event.
Last edited by nemaroller; Apr 16th, 2004 at 10:09 PM.
-
Apr 17th, 2004, 07:49 AM
#4
Thread Starter
Frenzied Member
The problem with setting enabled = false is that until the code behind the button has finished the user can keep clicking on the button over and over until the page is rendered again with the button disabled.
Cheers, i'll look at calling _dopostback instead of submiting th form.
Thanks.
-
Apr 17th, 2004, 10:05 AM
#5
I wonder how many charact
-
Apr 17th, 2004, 10:30 AM
#6
Thread Starter
Frenzied Member
Thanks for those links, just what i wanted.
-
Apr 17th, 2004, 12:16 PM
#7
Thread Starter
Frenzied Member
Finally got this working exactly as i wanted. Stops a button begin reclicked until processing from the first instance has finished. This code also works when there are validators on the page. Here's the code incase it's useful to anyone else.
VB Code:
Dim sb As New System.Text.StringBuilder
sb.Append("if (typeof(Page_ClientValidate) == 'function') { ")
sb.Append("if (Page_ClientValidate() == false) { return false; }} ")
sb.Append("this.value = 'Please wait...';")
sb.Append("this.disabled = true;")
sb.Append(GetPostBackEventReference(btnSubmit))
sb.Append(";")
If Not IsPostBack Then
btnSubmit.Attributes.Add("onclick", sb.ToString())
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|