disable button on click

Discussion in 'ASP .Net' started by nicholas, Dec 5, 2003.

  1. nicholas

    nicholas Guest

    how can I disable a button when the user clicks on it and the webform is
    validated.

    I want this to prevent the user from clicking twice and by this submitting
    the form twice.

    Thank you.

    This is what I tried, but it does nothing:

    <script runat="server">
    sub submit_it (Obj as Object, e as EventArgs)
    if (Page.IsValid) then
    BtnSubmit.text = Not(BtnSubmit.Enabled)
    end if
    End sub
    </script>
    nicholas, Dec 5, 2003
    #1
    1. Advertising

  2. set a page-level variable , boolean boolAllow
    then in ok click event

    if boolAllow = true then
    return
    bAllow = true
    btnOK.enable = false
    DO YOUR STUFF HERE
    btnok.enable = true ---- if u want
    boolAllow = false

    MIND - NOT REAL CODE ABOVE

    bart
    http://www.meshcode.net
    "nicholas" <> wrote in message
    news:eWE$...
    > how can I disable a button when the user clicks on it and the webform is
    > validated.
    >
    > I want this to prevent the user from clicking twice and by this submitting
    > the form twice.
    >
    > Thank you.
    >
    > This is what I tried, but it does nothing:
    >
    > <script runat="server">
    > sub submit_it (Obj as Object, e as EventArgs)
    > if (Page.IsValid) then
    > BtnSubmit.text = Not(BtnSubmit.Enabled)
    > end if
    > End sub
    > </script>
    >
    >
    Infant Newbie, Dec 5, 2003
    #2
    1. Advertising

  3. Nicholas,

    This javascript will do the trick for you. It only disables the button if
    the form passes validation:

    <script language="javascript">
    <!--
    var submitcount=0;

    function disableSubmit()
    {
    if (typeof(Page_ClientValidate)=='function')
    {
    if (Page_ClientValidate() == true)
    {
    return checkSubmit();
    }
    else
    {
    return true;
    }
    }
    else
    {
    return checkSubmit();
    }
    }

    function checkSubmit()
    {
    if (submitcount == 0)
    {
    submitcount++; return true;
    }
    else
    {
    alert('This form has already been submitted.'); return false;
    }
    }
    //-->
    </script>

    In VB.Net Attach it to your button like so:

    SubmitButton.Attributes.Add("onClick", "javascript: return
    disableSubmit();")


    If you'd like I've encapsulated this script and a method for attaching it to
    any button in a component I offer for free on my web site,
    www.aboutfortunate.com.

    Just go to the code library and then click the Javascript button in the menu
    on the left. The entire component's source code is available (as a .Net
    project) and it contains some other useful javascripts.


    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    Free code library at:
    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzche


    "nicholas" <> wrote in message
    news:eWE$...
    > how can I disable a button when the user clicks on it and the webform is
    > validated.
    >
    > I want this to prevent the user from clicking twice and by this submitting
    > the form twice.
    >
    > Thank you.
    >
    > This is what I tried, but it does nothing:
    >
    > <script runat="server">
    > sub submit_it (Obj as Object, e as EventArgs)
    > if (Page.IsValid) then
    > BtnSubmit.text = Not(BtnSubmit.Enabled)
    > end if
    > End sub
    > </script>
    >
    >
    S. Justin Gengo, Dec 5, 2003
    #3
  4. nicholas

    Kathy Burke Guest

    btnSubmit.enabled = False

    hth,

    Kathy

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Kathy Burke, Dec 5, 2003
    #4
  5. nicholas

    nicholas Guest

    Although I don't realy understand what you are trying to do, this is what I
    tried without succes:

    <script runat="server">
    dim boolAllow as boolean
    sub submit_it (Obj as Object, e as EventArgs)
    if boolAllow = true then
    return
    boolAllow = true
    BtnSubmit.enabled = false
    boolAllow = false
    if (Page.IsValid) then
    BtnSubmit.enabled = False
    end if
    end if
    End sub
    </script>



    "Infant Newbie" <> wrote in message
    news:bqq5j8$1nl$2surf.net...
    > set a page-level variable , boolean boolAllow
    > then in ok click event
    >
    > if boolAllow = true then
    > return
    > bAllow = true
    > btnOK.enable = false
    > DO YOUR STUFF HERE
    > btnok.enable = true ---- if u want
    > boolAllow = false
    >
    > MIND - NOT REAL CODE ABOVE
    >
    > bart
    > http://www.meshcode.net
    > "nicholas" <> wrote in message
    > news:eWE$...
    > > how can I disable a button when the user clicks on it and the webform is
    > > validated.
    > >
    > > I want this to prevent the user from clicking twice and by this

    submitting
    > > the form twice.
    > >
    > > Thank you.
    > >
    > > This is what I tried, but it does nothing:
    > >
    > > <script runat="server">
    > > sub submit_it (Obj as Object, e as EventArgs)
    > > if (Page.IsValid) then
    > > BtnSubmit.text = Not(BtnSubmit.Enabled)
    > > end if
    > > End sub
    > > </script>
    > >
    > >

    >
    >
    nicholas, Dec 5, 2003
    #5
  6. nicholas

    nicholas Guest

    That's what I tried first, but that does not work (although it doesn't
    generate an error):

    <script runat="server">
    sub submit_it (Obj as Object, e as EventArgs)
    BtnSubmit.enabled = false
    End sub
    </script>

    "Kathy Burke" <> wrote in message
    news:...
    >
    > btnSubmit.enabled = False
    >
    > hth,
    >
    > Kathy
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    nicholas, Dec 5, 2003
    #6
  7. nicholas

    nicholas Guest

    I tried to send you a mail, but your I got this error:
    450 <>: Recipient address rejected: Domain not
    found

    You'll find a mail link on my web site: www.squaresweb.com

    Thanks a lot for your help.



    "Infant Newbie" <> wrote in message
    news:bqvs95$ulf$2surf.net...
    > if u still need help send me mail and i will send u a working example
    >
    >
    >
    >
    > http://www.meshcode.net
    >
    >
    > "nicholas" <> wrote in message
    > news:...
    > > Although I don't realy understand what you are trying to do, this is

    what
    > I
    > > tried without succes:
    > >
    > > <script runat="server">
    > > dim boolAllow as boolean
    > > sub submit_it (Obj as Object, e as EventArgs)
    > > if boolAllow = true then
    > > return
    > > boolAllow = true
    > > BtnSubmit.enabled = false
    > > boolAllow = false
    > > if (Page.IsValid) then
    > > BtnSubmit.enabled = False
    > > end if
    > > end if
    > > End sub
    > > </script>
    > >
    > >
    > >
    > > "Infant Newbie" <> wrote in message
    > > news:bqq5j8$1nl$2surf.net...
    > > > set a page-level variable , boolean boolAllow
    > > > then in ok click event
    > > >
    > > > if boolAllow = true then
    > > > return
    > > > bAllow = true
    > > > btnOK.enable = false
    > > > DO YOUR STUFF HERE
    > > > btnok.enable = true ---- if u want
    > > > boolAllow = false
    > > >
    > > > MIND - NOT REAL CODE ABOVE
    > > >
    > > > bart
    > > > http://www.meshcode.net
    > > > "nicholas" <> wrote in message
    > > > news:eWE$...
    > > > > how can I disable a button when the user clicks on it and the

    webform
    > is
    > > > > validated.
    > > > >
    > > > > I want this to prevent the user from clicking twice and by this

    > > submitting
    > > > > the form twice.
    > > > >
    > > > > Thank you.
    > > > >
    > > > > This is what I tried, but it does nothing:
    > > > >
    > > > > <script runat="server">
    > > > > sub submit_it (Obj as Object, e as EventArgs)
    > > > > if (Page.IsValid) then
    > > > > BtnSubmit.text = Not(BtnSubmit.Enabled)
    > > > > end if
    > > > > End sub
    > > > > </script>
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    nicholas, Dec 8, 2003
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Purvi T
    Replies:
    0
    Views:
    831
    Purvi T
    Oct 19, 2004
  2. Sinity

    Disable button after first click

    Sinity, Nov 12, 2003, in forum: ASP .Net
    Replies:
    15
    Views:
    15,977
    nayak
    Sep 4, 2007
  3. Sinity

    Disable button after first click

    Sinity, Nov 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    420
    Sinity
    Nov 12, 2003
  4. Barry Gilmore

    Disable on button click

    Barry Gilmore, Oct 17, 2005, in forum: ASP .Net
    Replies:
    16
    Views:
    13,008
    JIMCO Software
    Oct 21, 2005
  5. Amy
    Replies:
    0
    Views:
    977
Loading...

Share This Page