Disable Submit Button

Discussion in 'ASP .Net' started by jack-e, Jun 20, 2005.

  1. jack-e

    jack-e Guest

    Hi,

    Can someone please provide me with an example of how to disable the
    submit button once clicked (using javascript i guess). Keep in mind I
    also have to invoke a server side function which processes the form.

    Thanks in advance.

    Jack
     
    jack-e, Jun 20, 2005
    #1
    1. Advertising

  2. jack-e wrote:
    > Hi,
    >
    > Can someone please provide me with an example of how to disable the
    > submit button once clicked (using javascript i guess). Keep in mind I
    > also have to invoke a server side function which processes the form.
    >
    > Thanks in advance.
    >
    > Jack
    >


    Use the Attributes collection to set the onclick to disabled the button
    and submit normally:

    button1.Attributes.Add("onclick","javascript:document.getElementById('"
    + button1.ClientID + "').disabled=true;" +
    this.GetPostBackEventReference(button1));

    reference:

    http://www.codeproject.com/useritems/DisableSubmitButton.asp

    --
    Craig Deelsnyder
    Microsoft MVP - ASP/ASP.NET
     
    Craig Deelsnyder, Jun 20, 2005
    #2
    1. Advertising

  3. Much shorter form:

    button1.Attributes.Add("onclick","this.disabled=true;return true;");

    Eliyahu

    "Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
    news:...
    > jack-e wrote:
    > > Hi,
    > >
    > > Can someone please provide me with an example of how to disable the
    > > submit button once clicked (using javascript i guess). Keep in mind I
    > > also have to invoke a server side function which processes the form.
    > >
    > > Thanks in advance.
    > >
    > > Jack
    > >

    >
    > Use the Attributes collection to set the onclick to disabled the button
    > and submit normally:
    >
    > button1.Attributes.Add("onclick","javascript:document.getElementById('"
    > + button1.ClientID + "').disabled=true;" +
    > this.GetPostBackEventReference(button1));
    >
    > reference:
    >
    > http://www.codeproject.com/useritems/DisableSubmitButton.asp
    >
    > --
    > Craig Deelsnyder
    > Microsoft MVP - ASP/ASP.NET
     
    Eliyahu Goldin, Jun 20, 2005
    #3
  4. Eliyahu Goldin wrote:
    > Much shorter form:
    >
    > button1.Attributes.Add("onclick","this.disabled=true;return true;");
    >
    > Eliyahu
    >
    > "Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
    > news:...
    >
    >>jack-e wrote:
    >>
    >>>Hi,
    >>>
    >>>Can someone please provide me with an example of how to disable the
    >>>submit button once clicked (using javascript i guess). Keep in mind I
    >>>also have to invoke a server side function which processes the form.
    >>>
    >>>Thanks in advance.
    >>>
    >>>Jack
    >>>

    >>
    >>Use the Attributes collection to set the onclick to disabled the button
    >>and submit normally:
    >>
    >>button1.Attributes.Add("onclick","javascript:document.getElementById('"
    >>+ button1.ClientID + "').disabled=true;" +
    >>this.GetPostBackEventReference(button1));
    >>
    >>reference:
    >>
    >>http://www.codeproject.com/useritems/DisableSubmitButton.asp
    >>
    >>--
    >>Craig Deelsnyder
    >>Microsoft MVP - ASP/ASP.NET

    >
    >
    >


    Hmmm, that didn't seem to work for me. Could you provide sample code if
    so? For completeness here....

    --
    Craig Deelsnyder
    Microsoft MVP - ASP/ASP.NET
     
    Craig Deelsnyder, Jun 20, 2005
    #4
  5. jack-e

    Patrice Guest

    Try to submit the from and then to disable the button. If you disable first
    the button, the button is not considered pressed (disabled control are not
    posted).

    Patrice

    --

    "Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> a écrit dans le message
    de news:%...
    > Eliyahu Goldin wrote:
    > > Much shorter form:
    > >
    > > button1.Attributes.Add("onclick","this.disabled=true;return true;");
    > >
    > > Eliyahu
    > >
    > > "Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
    > > news:...
    > >
    > >>jack-e wrote:
    > >>
    > >>>Hi,
    > >>>
    > >>>Can someone please provide me with an example of how to disable the
    > >>>submit button once clicked (using javascript i guess). Keep in mind I
    > >>>also have to invoke a server side function which processes the form.
    > >>>
    > >>>Thanks in advance.
    > >>>
    > >>>Jack
    > >>>
    > >>
    > >>Use the Attributes collection to set the onclick to disabled the button
    > >>and submit normally:
    > >>
    > >>button1.Attributes.Add("onclick","javascript:document.getElementById('"
    > >>+ button1.ClientID + "').disabled=true;" +
    > >>this.GetPostBackEventReference(button1));
    > >>
    > >>reference:
    > >>
    > >>http://www.codeproject.com/useritems/DisableSubmitButton.asp
    > >>
    > >>--
    > >>Craig Deelsnyder
    > >>Microsoft MVP - ASP/ASP.NET

    > >
    > >
    > >

    >
    > Hmmm, that didn't seem to work for me. Could you provide sample code if
    > so? For completeness here....
    >
    > --
    > Craig Deelsnyder
    > Microsoft MVP - ASP/ASP.NET
     
    Patrice, Jun 20, 2005
    #5
  6. Craig,

    You can check it on any server-side button. "this" is the client-side
    reference to the button itself and "return true" takes care about bubbling
    the event up.

    Eliyahu

    "Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
    news:%...
    > Eliyahu Goldin wrote:
    > > Much shorter form:
    > >
    > > button1.Attributes.Add("onclick","this.disabled=true;return true;");
    > >
    > > Eliyahu
    > >
    > > "Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
    > > news:...
    > >
    > >>jack-e wrote:
    > >>
    > >>>Hi,
    > >>>
    > >>>Can someone please provide me with an example of how to disable the
    > >>>submit button once clicked (using javascript i guess). Keep in mind I
    > >>>also have to invoke a server side function which processes the form.
    > >>>
    > >>>Thanks in advance.
    > >>>
    > >>>Jack
    > >>>
    > >>
    > >>Use the Attributes collection to set the onclick to disabled the button
    > >>and submit normally:
    > >>
    > >>button1.Attributes.Add("onclick","javascript:document.getElementById('"
    > >>+ button1.ClientID + "').disabled=true;" +
    > >>this.GetPostBackEventReference(button1));
    > >>
    > >>reference:
    > >>
    > >>http://www.codeproject.com/useritems/DisableSubmitButton.asp
    > >>
    > >>--
    > >>Craig Deelsnyder
    > >>Microsoft MVP - ASP/ASP.NET

    > >
    > >
    > >

    >
    > Hmmm, that didn't seem to work for me. Could you provide sample code if
    > so? For completeness here....
    >
    > --
    > Craig Deelsnyder
    > Microsoft MVP - ASP/ASP.NET
     
    Eliyahu Goldin, Jun 20, 2005
    #6
  7. Could be. This I didn't check. I've just optimized the size of the code.

    Eliyahu

    "Patrice" <> wrote in message
    news:eFj%...
    > Try to submit the from and then to disable the button. If you disable

    first
    > the button, the button is not considered pressed (disabled control are not
    > posted).
    >
    > Patrice
    >
    > --
    >
    > "Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> a écrit dans le

    message
    > de news:%...
    > > Eliyahu Goldin wrote:
    > > > Much shorter form:
    > > >
    > > > button1.Attributes.Add("onclick","this.disabled=true;return true;");
    > > >
    > > > Eliyahu
    > > >
    > > > "Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
    > > > news:...
    > > >
    > > >>jack-e wrote:
    > > >>
    > > >>>Hi,
    > > >>>
    > > >>>Can someone please provide me with an example of how to disable the
    > > >>>submit button once clicked (using javascript i guess). Keep in mind I
    > > >>>also have to invoke a server side function which processes the form.
    > > >>>
    > > >>>Thanks in advance.
    > > >>>
    > > >>>Jack
    > > >>>
    > > >>
    > > >>Use the Attributes collection to set the onclick to disabled the

    button
    > > >>and submit normally:
    > > >>

    > >
    >>button1.Attributes.Add("onclick","javascript:document.getElementById('"
    > > >>+ button1.ClientID + "').disabled=true;" +
    > > >>this.GetPostBackEventReference(button1));
    > > >>
    > > >>reference:
    > > >>
    > > >>http://www.codeproject.com/useritems/DisableSubmitButton.asp
    > > >>
    > > >>--
    > > >>Craig Deelsnyder
    > > >>Microsoft MVP - ASP/ASP.NET
    > > >
    > > >
    > > >

    > >
    > > Hmmm, that didn't seem to work for me. Could you provide sample code if
    > > so? For completeness here....
    > >
    > > --
    > > Craig Deelsnyder
    > > Microsoft MVP - ASP/ASP.NET

    >
    >
     
    Eliyahu Goldin, Jun 20, 2005
    #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. James Brett
    Replies:
    4
    Views:
    11,736
    James Brett
    Nov 26, 2003
  2. Ghafran Abbas
    Replies:
    0
    Views:
    4,241
    Ghafran Abbas
    Oct 12, 2004
  3. Jeff

    Disable Submit Button

    Jeff, Oct 18, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    5,926
    bruce barker
    Oct 18, 2004
  4. Paul Oakfleet
    Replies:
    1
    Views:
    858
    Chris Riesbeck
    Sep 10, 2003
  5. Chuck
    Replies:
    0
    Views:
    271
    Chuck
    Nov 10, 2003
Loading...

Share This Page