Disable button after first click

Discussion in 'ASP .Net' started by Sinity, Nov 12, 2003.

  1. Sinity

    Sinity Guest

    Anyone knows the method/codes to disable the clicked button after first
    click by using .aspx-- to prevent people to click many time when waiting for
    the server response.

    I tried to do this by adding a java script for the button. But, useless..

    Please help! Thank you
    Sinity, Nov 12, 2003
    #1
    1. Advertising

  2. Using Javascript(Client side
    You can add a javascript onclick handler in the .cs file as unde

    string x = "document.Form1.Button1.disabled=true"
    this.Button1.Attributes.Add("onclick",x)

    To do the same on the server side

    add the following to your button click event handler { i.e the function --private void Button1_Click(object sender, System.EventArgs e)
    this.Button1.Enabled=false
    =?Utf-8?B?VmlqYXkgR2FuZ2E=?=, Nov 12, 2003
    #2
    1. Advertising

  3. Sinity,

    I'm just about to post the code to do this on my website, but here you go:

    It stops the submit, but even better it calls some of the same .Net client
    side code and doesn't disable the button if any required field validators
    aren't valid and the page doesn't actually submit.

    <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>

    Attach it to your button like so:

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


    Sincerely,

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzche


    "Sinity" <> wrote in message
    news:%...
    > Anyone knows the method/codes to disable the clicked button after first
    > click by using .aspx-- to prevent people to click many time when waiting

    for
    > the server response.
    >
    > I tried to do this by adding a java script for the button. But, useless..
    >
    > Please help! Thank you
    >
    >
    S. Justin Gengo, Nov 12, 2003
    #3
  4. Sinity

    Homa Guest

    > if (Page_ClientValidate() == true)
    > {
    > return checkSubmit();
    > }
    > else
    > {
    > return true; <<< ----- You mean return false; right?
    > }


    Homa Wong


    "S. Justin Gengo" <> wrote in message news:<>...
    > Sinity,
    >
    > I'm just about to post the code to do this on my website, but here you go:
    >
    > It stops the submit, but even better it calls some of the same .Net client
    > side code and doesn't disable the button if any required field validators
    > aren't valid and the page doesn't actually submit.
    >
    > <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>
    >
    > Attach it to your button like so:
    >
    > SubmitButton.Attributes.Add("onClick", "javascript: return
    > disableSubmit();")
    >
    >
    > Sincerely,
    >
    > --
    > S. Justin Gengo, MCP
    > Web Developer
    >
    > Free code library at:
    > www.aboutfortunate.com
    >
    > "Out of chaos comes order."
    > Nietzche
    >
    >
    > "Sinity" <> wrote in message
    > news:%...
    > > Anyone knows the method/codes to disable the clicked button after first
    > > click by using .aspx-- to prevent people to click many time when waiting

    > for
    > > the server response.
    > >
    > > I tried to do this by adding a java script for the button. But, useless..
    > >
    > > Please help! Thank you
    > >
    > >
    Homa, Nov 12, 2003
    #4
  5. Sinity

    Sinity Guest

    As the server response is slow something because of the network traffic,
    users click again and again.

    how can I manage this problem in aspx level?

    I am using VB.NET as the devevelopment tool


    "S. Justin Gengo" <> ¼¶¼g©ó¶l¥ó·s»D
    :...
    > Sinity,
    >
    > I'm just about to post the code to do this on my website, but here you go:
    >
    > It stops the submit, but even better it calls some of the same .Net client
    > side code and doesn't disable the button if any required field validators
    > aren't valid and the page doesn't actually submit.
    >
    > <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>
    >
    > Attach it to your button like so:
    >
    > SubmitButton.Attributes.Add("onClick", "javascript: return
    > disableSubmit();")
    >
    >
    > Sincerely,
    >
    > --
    > S. Justin Gengo, MCP
    > Web Developer
    >
    > Free code library at:
    > www.aboutfortunate.com
    >
    > "Out of chaos comes order."
    > Nietzche
    >
    >
    > "Sinity" <> wrote in message
    > news:%...
    > > Anyone knows the method/codes to disable the clicked button after first
    > > click by using .aspx-- to prevent people to click many time when waiting

    > for
    > > the server response.
    > >
    > > I tried to do this by adding a java script for the button. But,

    useless..
    > >
    > > Please help! Thank you
    > >
    > >

    >
    >
    Sinity, Nov 13, 2003
    #5
  6. Sinity

    Scott M. Guest

    If IsPostBack Then
    button.enabled = false
    End If

    "Sinity" <> wrote in message
    news:%...
    > Anyone knows the method/codes to disable the clicked button after first
    > click by using .aspx-- to prevent people to click many time when waiting

    for
    > the server response.
    >
    > I tried to do this by adding a java script for the button. But, useless..
    >
    > Please help! Thank you
    >
    >
    Scott M., Nov 13, 2003
    #6
  7. No, "return false;" is correct. Try it out.

    Sincerely,

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzche


    "Homa" <> wrote in message
    news:...
    > > if (Page_ClientValidate() == true)
    > > {
    > > return checkSubmit();
    > > }
    > > else
    > > {
    > > return true; <<< ----- You mean return false; right?
    > > }

    >
    > Homa Wong
    >
    >
    > "S. Justin Gengo" <> wrote in message

    news:<>...
    > > Sinity,
    > >
    > > I'm just about to post the code to do this on my website, but here you

    go:
    > >
    > > It stops the submit, but even better it calls some of the same .Net

    client
    > > side code and doesn't disable the button if any required field

    validators
    > > aren't valid and the page doesn't actually submit.
    > >
    > > <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>
    > >
    > > Attach it to your button like so:
    > >
    > > SubmitButton.Attributes.Add("onClick", "javascript: return
    > > disableSubmit();")
    > >
    > >
    > > Sincerely,
    > >
    > > --
    > > S. Justin Gengo, MCP
    > > Web Developer
    > >
    > > Free code library at:
    > > www.aboutfortunate.com
    > >
    > > "Out of chaos comes order."
    > > Nietzche
    > >
    > >
    > > "Sinity" <> wrote in message
    > > news:%...
    > > > Anyone knows the method/codes to disable the clicked button after

    first
    > > > click by using .aspx-- to prevent people to click many time when

    waiting
    > > for
    > > > the server response.
    > > >
    > > > I tried to do this by adding a java script for the button. But,

    useless..
    > > >
    > > > Please help! Thank you
    > > >
    > > >
    S. Justin Gengo, Nov 13, 2003
    #7
  8. Sinity

    Homa Wong Guest

    ?? But I thought you wrote "return true" ??

    Homa Wong


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Homa Wong, Nov 13, 2003
    #8
  9. Homa,

    Now I've confused myself! Yes, it has to be "return true;".

    This is because the submit button's click event fires off two different
    asp.net javascripts. One is the javascript I'm tying into:
    Page_ClientValidate, the other is a javascript that checks the required
    field validators.

    At the point in question inside of my javascript if the Button doesn't get
    clicked (which is what "return false;" would cause then any validators on
    the page wouldn't get displayed properly.

    Sincerely,

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzche


    "Homa Wong" <> wrote in message
    news:...
    >
    > ?? But I thought you wrote "return true" ??
    >
    > Homa Wong
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    S. Justin Gengo, Nov 13, 2003
    #9
  10. Sinity

    Homa Guest

    haha,

    ...."Out of chaos comes order."


    Homa Wong

    "S. Justin Gengo" <> wrote in message news:<>...
    > Homa,
    >
    > Now I've confused myself! Yes, it has to be "return true;".
    >
    > This is because the submit button's click event fires off two different
    > asp.net javascripts. One is the javascript I'm tying into:
    > Page_ClientValidate, the other is a javascript that checks the required
    > field validators.
    >
    > At the point in question inside of my javascript if the Button doesn't get
    > clicked (which is what "return false;" would cause then any validators on
    > the page wouldn't get displayed properly.
    >
    > Sincerely,
    >
    > --
    > S. Justin Gengo, MCP
    > Web Developer
    >
    > Free code library at:
    > www.aboutfortunate.com
    >
    > "Out of chaos comes order."
    > Nietzche
    >
    >
    > "Homa Wong" <> wrote in message
    > news:...
    > >
    > > ?? But I thought you wrote "return true" ??
    > >
    > > Homa Wong
    > >
    > >
    > > *** Sent via Developersdex http://www.developersdex.com ***
    > > Don't just participate in USENET...get rewarded for it!
    Homa, Nov 13, 2003
    #10
  11. LOL

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzche


    "Homa" <> wrote in message
    news:...
    > haha,
    >
    > ..."Out of chaos comes order."
    >
    >
    > Homa Wong
    >
    > "S. Justin Gengo" <> wrote in message

    news:<>...
    > > Homa,
    > >
    > > Now I've confused myself! Yes, it has to be "return true;".
    > >
    > > This is because the submit button's click event fires off two different
    > > asp.net javascripts. One is the javascript I'm tying into:
    > > Page_ClientValidate, the other is a javascript that checks the required
    > > field validators.
    > >
    > > At the point in question inside of my javascript if the Button doesn't

    get
    > > clicked (which is what "return false;" would cause then any validators

    on
    > > the page wouldn't get displayed properly.
    > >
    > > Sincerely,
    > >
    > > --
    > > S. Justin Gengo, MCP
    > > Web Developer
    > >
    > > Free code library at:
    > > www.aboutfortunate.com
    > >
    > > "Out of chaos comes order."
    > > Nietzche
    > >
    > >
    > > "Homa Wong" <> wrote in message
    > > news:...
    > > >
    > > > ?? But I thought you wrote "return true" ??
    > > >
    > > > Homa Wong
    > > >
    > > >
    > > > *** Sent via Developersdex http://www.developersdex.com ***
    > > > Don't just participate in USENET...get rewarded for it!
    S. Justin Gengo, Nov 13, 2003
    #11
  12. You could try using an if/then that checks a session variable to see if it's
    set to true. Then inside of the if/then set the session variable to be
    false. That way if the form is submitted a second time the code inside the
    if/then won't be run a second time...

    Sincerely,

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzche


    "Sinity" <> wrote in message
    news:...
    > As the server response is slow something because of the network traffic,
    > users click again and again.
    >
    > how can I manage this problem in aspx level?
    >
    > I am using VB.NET as the devevelopment tool
    >
    >
    > "S. Justin Gengo" <> ¼¶¼g©ó¶l¥ó·s»D
    > :...
    > > Sinity,
    > >
    > > I'm just about to post the code to do this on my website, but here you

    go:
    > >
    > > It stops the submit, but even better it calls some of the same .Net

    client
    > > side code and doesn't disable the button if any required field

    validators
    > > aren't valid and the page doesn't actually submit.
    > >
    > > <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>
    > >
    > > Attach it to your button like so:
    > >
    > > SubmitButton.Attributes.Add("onClick", "javascript: return
    > > disableSubmit();")
    > >
    > >
    > > Sincerely,
    > >
    > > --
    > > S. Justin Gengo, MCP
    > > Web Developer
    > >
    > > Free code library at:
    > > www.aboutfortunate.com
    > >
    > > "Out of chaos comes order."
    > > Nietzche
    > >
    > >
    > > "Sinity" <> wrote in message
    > > news:%...
    > > > Anyone knows the method/codes to disable the clicked button after

    first
    > > > click by using .aspx-- to prevent people to click many time when

    waiting
    > > for
    > > > the server response.
    > > >
    > > > I tried to do this by adding a java script for the button. But,

    > useless..
    > > >
    > > > Please help! Thank you
    > > >
    > > >

    > >
    > >

    >
    >
    S. Justin Gengo, Nov 13, 2003
    #12
  13. Sinity

    Scott M. Guest

    This is very basic ASP.NET stuff:

    If IsPostBack Then
    button.enabled = false
    End If

    The ability to determine if a form is being submitted for the first time is
    already built into the ASP.NET architecture.

    "S. Justin Gengo" <> wrote in message
    news:u%...
    > You could try using an if/then that checks a session variable to see if

    it's
    > set to true. Then inside of the if/then set the session variable to be
    > false. That way if the form is submitted a second time the code inside the
    > if/then won't be run a second time...
    >
    > Sincerely,
    >
    > --
    > S. Justin Gengo, MCP
    > Web Developer
    >
    > Free code library at:
    > www.aboutfortunate.com
    >
    > "Out of chaos comes order."
    > Nietzche
    >
    >
    > "Sinity" <> wrote in message
    > news:...
    > > As the server response is slow something because of the network traffic,
    > > users click again and again.
    > >
    > > how can I manage this problem in aspx level?
    > >
    > > I am using VB.NET as the devevelopment tool
    > >
    > >
    > > "S. Justin Gengo" <> ¼¶¼g©ó¶l¥ó·s»D
    > > :...
    > > > Sinity,
    > > >
    > > > I'm just about to post the code to do this on my website, but here you

    > go:
    > > >
    > > > It stops the submit, but even better it calls some of the same .Net

    > client
    > > > side code and doesn't disable the button if any required field

    > validators
    > > > aren't valid and the page doesn't actually submit.
    > > >
    > > > <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>
    > > >
    > > > Attach it to your button like so:
    > > >
    > > > SubmitButton.Attributes.Add("onClick", "javascript: return
    > > > disableSubmit();")
    > > >
    > > >
    > > > Sincerely,
    > > >
    > > > --
    > > > S. Justin Gengo, MCP
    > > > Web Developer
    > > >
    > > > Free code library at:
    > > > www.aboutfortunate.com
    > > >
    > > > "Out of chaos comes order."
    > > > Nietzche
    > > >
    > > >
    > > > "Sinity" <> wrote in message
    > > > news:%...
    > > > > Anyone knows the method/codes to disable the clicked button after

    > first
    > > > > click by using .aspx-- to prevent people to click many time when

    > waiting
    > > > for
    > > > > the server response.
    > > > >
    > > > > I tried to do this by adding a java script for the button. But,

    > > useless..
    > > > >
    > > > > Please help! Thank you
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Scott M., Nov 13, 2003
    #13
  14. Scott,

    Maybe I misunderstood sinity, but I thought the problem was keeping the user
    from clicking the submit button a second time before the postback to the
    server was complete.

    If that happens (say when a user is submitting an order for processing) they
    would end up with two orders. It wouldn't matter if you disable the button
    from server side code like in the example you gave because back on the
    client the button would still be enabled until the round trip of the post
    back is completed. Sinity says that the server process takes a long time
    which means that the client has plenty of time to try clicking submit again.

    The javascript I supplied disables the button client side, but only if the
    client has javascript. I think Sinity is asking for a way to keep a second
    submit from processing if it does escape the javascript. I only know of two
    ways to do that. One is to use a session variable like I suggested. The
    other would only work if information is being databased. As long as the
    database has a timestamp, the information being entered could be checked
    against existing entries to see if there is an entry that contains identical
    info. And if an identical entry is found, check its timestamp and stop the
    processing if the timestamps are, say, up to only 30 seconds apart.

    Sincerely,

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzche


    "Scott M." <> wrote in message
    news:...
    > This is very basic ASP.NET stuff:
    >
    > If IsPostBack Then
    > button.enabled = false
    > End If
    >
    > The ability to determine if a form is being submitted for the first time

    is
    > already built into the ASP.NET architecture.
    >
    > "S. Justin Gengo" <> wrote in message
    > news:u%...
    > > You could try using an if/then that checks a session variable to see if

    > it's
    > > set to true. Then inside of the if/then set the session variable to be
    > > false. That way if the form is submitted a second time the code inside

    the
    > > if/then won't be run a second time...
    > >
    > > Sincerely,
    > >
    > > --
    > > S. Justin Gengo, MCP
    > > Web Developer
    > >
    > > Free code library at:
    > > www.aboutfortunate.com
    > >
    > > "Out of chaos comes order."
    > > Nietzche
    > >
    > >
    > > "Sinity" <> wrote in message
    > > news:...
    > > > As the server response is slow something because of the network

    traffic,
    > > > users click again and again.
    > > >
    > > > how can I manage this problem in aspx level?
    > > >
    > > > I am using VB.NET as the devevelopment tool
    > > >
    > > >
    > > > "S. Justin Gengo" <> ¼¶¼g©ó¶l¥ó·s»D
    > > > :...
    > > > > Sinity,
    > > > >
    > > > > I'm just about to post the code to do this on my website, but here

    you
    > > go:
    > > > >
    > > > > It stops the submit, but even better it calls some of the same .Net

    > > client
    > > > > side code and doesn't disable the button if any required field

    > > validators
    > > > > aren't valid and the page doesn't actually submit.
    > > > >
    > > > > <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>
    > > > >
    > > > > Attach it to your button like so:
    > > > >
    > > > > SubmitButton.Attributes.Add("onClick", "javascript: return
    > > > > disableSubmit();")
    > > > >
    > > > >
    > > > > Sincerely,
    > > > >
    > > > > --
    > > > > S. Justin Gengo, MCP
    > > > > Web Developer
    > > > >
    > > > > Free code library at:
    > > > > www.aboutfortunate.com
    > > > >
    > > > > "Out of chaos comes order."
    > > > > Nietzche
    > > > >
    > > > >
    > > > > "Sinity" <> wrote in message
    > > > > news:%...
    > > > > > Anyone knows the method/codes to disable the clicked button after

    > > first
    > > > > > click by using .aspx-- to prevent people to click many time when

    > > waiting
    > > > > for
    > > > > > the server response.
    > > > > >
    > > > > > I tried to do this by adding a java script for the button. But,
    > > > useless..
    > > > > >
    > > > > > Please help! Thank you
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    S. Justin Gengo, Nov 14, 2003
    #14
  15. Sinity

    Scott M. Guest

    Yes, you're right. I think it was me who misunderstood. Thanks.


    "S. Justin Gengo" <> wrote in message
    news:...
    > Scott,
    >
    > Maybe I misunderstood sinity, but I thought the problem was keeping the

    user
    > from clicking the submit button a second time before the postback to the
    > server was complete.
    >
    > If that happens (say when a user is submitting an order for processing)

    they
    > would end up with two orders. It wouldn't matter if you disable the button
    > from server side code like in the example you gave because back on the
    > client the button would still be enabled until the round trip of the post
    > back is completed. Sinity says that the server process takes a long time
    > which means that the client has plenty of time to try clicking submit

    again.
    >
    > The javascript I supplied disables the button client side, but only if the
    > client has javascript. I think Sinity is asking for a way to keep a second
    > submit from processing if it does escape the javascript. I only know of

    two
    > ways to do that. One is to use a session variable like I suggested. The
    > other would only work if information is being databased. As long as the
    > database has a timestamp, the information being entered could be checked
    > against existing entries to see if there is an entry that contains

    identical
    > info. And if an identical entry is found, check its timestamp and stop the
    > processing if the timestamps are, say, up to only 30 seconds apart.
    >
    > Sincerely,
    >
    > --
    > S. Justin Gengo, MCP
    > Web Developer
    >
    > Free code library at:
    > www.aboutfortunate.com
    >
    > "Out of chaos comes order."
    > Nietzche
    >
    >
    > "Scott M." <> wrote in message
    > news:...
    > > This is very basic ASP.NET stuff:
    > >
    > > If IsPostBack Then
    > > button.enabled = false
    > > End If
    > >
    > > The ability to determine if a form is being submitted for the first time

    > is
    > > already built into the ASP.NET architecture.
    > >
    > > "S. Justin Gengo" <> wrote in message
    > > news:u%...
    > > > You could try using an if/then that checks a session variable to see

    if
    > > it's
    > > > set to true. Then inside of the if/then set the session variable to be
    > > > false. That way if the form is submitted a second time the code inside

    > the
    > > > if/then won't be run a second time...
    > > >
    > > > Sincerely,
    > > >
    > > > --
    > > > S. Justin Gengo, MCP
    > > > Web Developer
    > > >
    > > > Free code library at:
    > > > www.aboutfortunate.com
    > > >
    > > > "Out of chaos comes order."
    > > > Nietzche
    > > >
    > > >
    > > > "Sinity" <> wrote in message
    > > > news:...
    > > > > As the server response is slow something because of the network

    > traffic,
    > > > > users click again and again.
    > > > >
    > > > > how can I manage this problem in aspx level?
    > > > >
    > > > > I am using VB.NET as the devevelopment tool
    > > > >
    > > > >
    > > > > "S. Justin Gengo" <> ¼¶¼g©ó¶l¥ó·s»D
    > > > > :...
    > > > > > Sinity,
    > > > > >
    > > > > > I'm just about to post the code to do this on my website, but here

    > you
    > > > go:
    > > > > >
    > > > > > It stops the submit, but even better it calls some of the same

    ..Net
    > > > client
    > > > > > side code and doesn't disable the button if any required field
    > > > validators
    > > > > > aren't valid and the page doesn't actually submit.
    > > > > >
    > > > > > <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>
    > > > > >
    > > > > > Attach it to your button like so:
    > > > > >
    > > > > > SubmitButton.Attributes.Add("onClick", "javascript: return
    > > > > > disableSubmit();")
    > > > > >
    > > > > >
    > > > > > Sincerely,
    > > > > >
    > > > > > --
    > > > > > S. Justin Gengo, MCP
    > > > > > Web Developer
    > > > > >
    > > > > > Free code library at:
    > > > > > www.aboutfortunate.com
    > > > > >
    > > > > > "Out of chaos comes order."
    > > > > > Nietzche
    > > > > >
    > > > > >
    > > > > > "Sinity" <> wrote in message
    > > > > > news:%...
    > > > > > > Anyone knows the method/codes to disable the clicked button

    after
    > > > first
    > > > > > > click by using .aspx-- to prevent people to click many time when
    > > > waiting
    > > > > > for
    > > > > > > the server response.
    > > > > > >
    > > > > > > I tried to do this by adding a java script for the button. But,
    > > > > useless..
    > > > > > >
    > > > > > > Please help! Thank you
    > > > > > >
    > > > > > >
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Scott M., Nov 14, 2003
    #15
  16. Sinity

    nayak

    Joined:
    Sep 4, 2007
    Messages:
    2
    Here was my straightforward solution to the problem:

    javascript file snippet:
    ------------------------------------------------
    function disableButton(btnID, btnValGroup) {
    if (Page_ClientValidate(btnValGroup) == true) {
    document.forms[0].submit();
    document.getElementById(btnID).value = "Processing...";
    window.setTimeout("document.getElementById('" + btnID + "').disabled = true", 0);
    return true;
    }
    else {
    return false;
    }
    }


    aspx file snippet:
    ------------------------------------------------
    <asp:RequiredFieldValidator ID="rfvName" runat="server" Text="*" ControlToValidate="txtName" Display="Dynamic" ValidationGroup="SubmitName" />
    <asp:Label ID="lblName" runat="server" AssociatedControlID="txtName"
    Text="Name" />
    <asp:TextBox ID="txtName" runat="server" />
    <asp:Button ID="btnSubmitName" runat="server" ToolTip="Submit name" Text="SUBMIT NAME" OnClick="btnSubmitName_Click" ValidationGroup="SubmitName" />


    cs file snippet:
    ------------------------------------------------
    protected void Page_Load(object sender, EventArgs e)
    {
    // Check if initial page load
    if (!Page.IsPostBack)
    {
    btnSubmitName.OnClientClick = "return disableButton('" + btnSubmitName.ClientID + "','" + btnSubmitName.ValidationGroup + "');";
    }
    }

    protected void btnSubmitName_Click(object sender, EventArgs e)
    {
    // Check if page is valid
    if (Page.IsValid)
    {
    // Remove the sleep mechanism from final code
    System.Threading.Thread.Sleep(2000);
    lblFeedback.Text = "Submitted Name: " + txtName.Text.Trim() + " at " + DateTime.Now.ToString("H:mm:ss tt");
    }
    }
    nayak, Sep 4, 2007
    #16
    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. Sinity

    Disable button after first click

    Sinity, Nov 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    417
    Sinity
    Nov 12, 2003
  2. Chris  Ashley
    Replies:
    1
    Views:
    2,807
    =?Utf-8?B?RGF2aWQgSmVzc2Vl?=
    Dec 16, 2005
  3. GS
    Replies:
    11
    Views:
    39,224
  4. Stuart Quinn

    Disable a button on first click

    Stuart Quinn, Aug 5, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    617
  5. Sinity

    Disable button after first click

    Sinity, Nov 12, 2003, in forum: ASP General
    Replies:
    1
    Views:
    140
    Ray at
    Nov 12, 2003
Loading...

Share This Page