Results 1 to 4 of 4

Thread: [RESOLVED] ImageButton clicking twice or more...

  1. #1

    Thread Starter
    Hyperactive Member JMvVliet's Avatar
    Join Date
    May 2001
    Location
    Papendrecht, Netherlands
    Posts
    310

    Resolved [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:
    1. sJavaScript += "if (typeof(Page_ClientValidate) == 'function') "
    2. sJavaScript += "{ if (Page_ClientValidate() == false) "
    3. sJavaScript += "{ return false; }"
    4. sJavaScript += "} this.src= images\btnInvisible.jpg';"
    5. sJavaScript += "this.disabled = true;"
    6. sJavaScript += btn.Page.GetPostBackEventReference(btn) & ";"
    7.  
    8. 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

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539

    Re: ImageButton clicking twice or more...

    use the javascripts confirm function combined with getElementByIdto find the button and so on

  3. #3

    Thread Starter
    Hyperactive Member JMvVliet's Avatar
    Join Date
    May 2001
    Location
    Papendrecht, Netherlands
    Posts
    310

    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:
    1. sJavaScript += "if (typeof(Page_ClientValidate) == 'function') "
    2. sJavaScript += "{ if (Page_ClientValidate() == false) "
    3. sJavaScript += "{ return false; }}"
    4. [color=red]sJavaScript += " if (confirm('Save?[color=red]') == 0) { return false; }"[/color][/color]
    5. sJavaScript += "this.src= images\btnInvisible.jpg';"
    6. sJavaScript += "this.disabled = true;"
    7. sJavaScript += btn.Page.GetPostBackEventReference(btn) & ";"
    8.  
    9. btn.Attributes.Add("onclick", sJavaScript)

  4. #4

    Thread Starter
    Hyperactive Member JMvVliet's Avatar
    Join Date
    May 2001
    Location
    Papendrecht, Netherlands
    Posts
    310

    Re: [RESOLVED] ImageButton clicking twice or more...

    Have found the solution:

    VB Code:
    1. Dim sb As New System.Text.StringBuilder
    2.         sb.Append("if (typeof(Page_ClientValidate) == 'function') { ")
    3.         sb.Append("if (Page_ClientValidate() == false) { return false; }} ")
    4.         sb.Append("var answer = confirm('Save?'); ")
    5.         sb.Append("if (answer) { ")
    6.         sb.Append("this.enabled = false;")
    7.         sb.Append(Me.Page.GetPostBackEventReference(Me.ImageButton1))
    8.         sb.Append("; ")
    9.         sb.Append("document.Form1.submit; }")
    10.         sb.Append(" else {")
    11.         sb.Append(" return false; }")
    12.         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
  •  



Click Here to Expand Forum to Full Width