Re: How to disable the users to submit a page for a second time?

From: Rick Spiewak (rickspiewak_at_mindspring.com)
Date: 05/08/04


Date: Fri, 7 May 2004 23:11:40 -0400

Here is an example of how I do this - it combines code in the code-behind
and javascript. The </form> and </body> tags are there to show where to use
this:

                      </form>

                        <%if disableMe then%>

                        <script language="javascript">

                                                var disabled = true;

document.all.btnDisable.disabled = true;

                        </script>

                        <%else%>

                        <script language="javascript">

                                                var disabled = false;

document.all.btnDisable.disabled = false;

                        </script>

                        <%end if%>

                        <script language="javascript">

                                    function shouldsubmit()

                                    {

                                    if (disabled==true)

                                                {

                                                return false;

                                                }

                                    else

                                                {

                                                disabled = true;

                                                return true;

                                                }

                                    }

                        </script>

            </body>

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

        If Not Session("disableMe") Is Nothing Then

            disableMe = Session("disableMe")

        End If

    End Sub

    Protected disableMe As Boolean = False

    Private Sub btnDisable_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnDisable.Click

        disableMe = True

        Session("disableMe") = disableMe

    End Sub

"Mario Vargas" <anonymous@discussions.microsoft.com> wrote in message
news:678F95BB-507C-4566-AF1D-2E0FA3AE3A88@microsoft.com...
> Hi all,
> I have a login form that uses custom validators and I'm trying to stop the
users to submit this form twice. When I disable the button I don't know why,
but the request is cancelled. It seems that the page gets invalid and it
never gets the server, but why?.
> I've tried using a hidden control which is increased by one every time the
user presses the button; the login process runs only when the control has
the value of 1. So when the user presses the button twice, the firts request
is made ok, but the user is not redirected from the login page because the
second request is processed (the login process is not run because the
control has the value of 2).
> Any help wolud be really appreciated.
> God Bless.