|
-
Sep 11th, 2006, 08:14 AM
#1
Thread Starter
Hyperactive Member
[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
-
Sep 11th, 2006, 08:46 AM
#2
Frenzied Member
Re: ImageButton clicking twice or more...
use the javascripts confirm function combined with getElementByIdto find the button and so on
-
Sep 11th, 2006, 09:13 AM
#3
Thread Starter
Hyperactive Member
Re: ImageButton clicking twice or more...
 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)
-
Sep 12th, 2006, 02:43 AM
#4
Thread Starter
Hyperactive Member
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())
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
|