[RESOLVED] ImageButton clicking twice or more...
Hi all,
I want to prevent users in ASP .NET 1.1 to click an ImageButton that saves data to a database twice. Ive done it this way (it works really nice):
VB Code:
sJavaScript += "if (typeof(Page_ClientValidate) == 'function') "
sJavaScript += "{ if (Page_ClientValidate() == false) "
sJavaScript += "{ return false; }"
sJavaScript += "} this.src= images\btnInvisible.jpg';"
sJavaScript += "this.disabled = true;"
sJavaScript += btn.Page.GetPostBackEventReference(btn) & ";"
btn.Attributes.Add("onclick", sJavaScript)
The question I have is this one: how can I implement a question if the user wants to save the data? If the user clicks ok, the button should be disabled, if the user clicks cancel, nothing should happen and the button remains clickable.
Could anyone help me with this?
Thanx in advance,
JMvV
Re: ImageButton clicking twice or more...
use the javascripts confirm function combined with getElementByIdto find the button and so on
Re: ImageButton clicking twice or more...
Quote:
Originally Posted by kovan
use the javascripts confirm function combined with getElementByIdto find the button and so on
Ok, I have tried to include that, but I'm not getting it to work. I have tried this:
VB Code:
sJavaScript += "if (typeof(Page_ClientValidate) == 'function') "
sJavaScript += "{ if (Page_ClientValidate() == false) "
sJavaScript += "{ return false; }}"
[color=red]sJavaScript += " if (confirm('Save?[color=red]') == 0) { return false; }"[/color][/color]
sJavaScript += "this.src= images\btnInvisible.jpg';"
sJavaScript += "this.disabled = true;"
sJavaScript += btn.Page.GetPostBackEventReference(btn) & ";"
btn.Attributes.Add("onclick", sJavaScript)
Re: [RESOLVED] ImageButton clicking twice or more...
Have found the solution:
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("var answer = confirm('Save?'); ")
sb.Append("if (answer) { ")
sb.Append("this.enabled = false;")
sb.Append(Me.Page.GetPostBackEventReference(Me.ImageButton1))
sb.Append("; ")
sb.Append("document.Form1.submit; }")
sb.Append(" else {")
sb.Append(" return false; }")
ImageButton1.Attributes.Add("onclick", sb.ToString())