Disable Linkbutton Before Postback?

Discussion in 'ASP .Net' started by Al Cohen, Dec 19, 2003.

  1. Al Cohen

    Al Cohen Guest

    I'm using a LinkButton to call some code, then do a redirect. The code
    does some queries, sends some emails, and takes a few moments before the
    redirect is performed.

    I'd like to disable my LinkButton during this period to prevent multiple
    submissions. (Obviously) the disabling should be done at the client
    side to prevent any delay. I've tried adding some javascript to
    LinkButton.Attributes:

    LinkButton1.Attributes.Add("onclick", "this.href='javascript:void(0)'"
    + this.GetPostBackEventReference(this.LinkButton1));

    but this doesn't disable the LinkButton. I also tried:

    LinkButton1.Attributes.Add("onclick", "this.href='javascript:void(0)'");

    which disables the link, but never does the postback.

    This seems like a very important thing to be able to do, and thus it
    should be reasonably easy - what am I missing?

    Alternatively, perhaps there's something clever that I can do on the
    server side to "short circuit" subsequent postbacks?

    Thanks,

    Al Cohen
     
    Al Cohen, Dec 19, 2003
    #1
    1. Advertising

  2. Hi Al,

    I've had that same issue. Usually you have to attach the script code to the
    form's OnSubmit().

    Actually what I found is that if you disable the button that you're binding
    events to the button's event doesn't fire because the button doesn't show up
    in the post variable list. Hiding the button actually works better.

    I usually do this in the HTML but you should be able to do the same with
    attributes:

    <form id="frmOrderForm"
    onsubmit="this.btnSubmit.style.display='none';document.getElementById('WaitN
    ote').style.display='inline';return true;" ... >

    This code hides the button and shows an area that has a message.

    Works real well, except that I have an animated Gif in there and it doesn't
    animate - some bug in IE related to a hidden image not animating, it works
    with Mozilla...

    +++ Rick ---

    --

    Rick Strahl
    West Wind Technologies
    http://www.west-wind.com/
    http://www.west-wind.com/blog/
    ----------------------------------
    Making waves on the Web


    "Al Cohen" <-o-r-n-e-l-l.edu> wrote in message
    news:D...
    > I'm using a LinkButton to call some code, then do a redirect. The code
    > does some queries, sends some emails, and takes a few moments before the
    > redirect is performed.
    >
    > I'd like to disable my LinkButton during this period to prevent multiple
    > submissions. (Obviously) the disabling should be done at the client
    > side to prevent any delay. I've tried adding some javascript to
    > LinkButton.Attributes:
    >
    > LinkButton1.Attributes.Add("onclick", "this.href='javascript:void(0)'"
    > + this.GetPostBackEventReference(this.LinkButton1));
    >
    > but this doesn't disable the LinkButton. I also tried:
    >
    > LinkButton1.Attributes.Add("onclick", "this.href='javascript:void(0)'");
    >
    > which disables the link, but never does the postback.
    >
    > This seems like a very important thing to be able to do, and thus it
    > should be reasonably easy - what am I missing?
    >
    > Alternatively, perhaps there's something clever that I can do on the
    > server side to "short circuit" subsequent postbacks?
    >
    > Thanks,
    >
    > Al Cohen
    >
    >
     
    Rick Strahl [MVP], Dec 19, 2003
    #2
    1. Advertising

  3. Al Cohen

    A Guest

    Hi,
    a solution that allways works, even if the user presses F5, or disables
    javascript

    I normaly insert a database value (ID, Identity) in a hidden form, when the
    "updating" or other stuff takes place, it first checks if the value (ID) is
    in the database, if it is there updating takes place and the ID is deleted,
    if it is NOT there i tell the user that their data is allready saved,
    problerly because they hit the submit button twice...

    Regards,

    Agge

    "Rick Strahl [MVP]" <> skrev i en meddelelse
    news:%...
    > Hi Al,
    >
    > I've had that same issue. Usually you have to attach the script code to

    the
    > form's OnSubmit().
    >
    > Actually what I found is that if you disable the button that you're

    binding
    > events to the button's event doesn't fire because the button doesn't show

    up
    > in the post variable list. Hiding the button actually works better.
    >
    > I usually do this in the HTML but you should be able to do the same with
    > attributes:
    >
    > <form id="frmOrderForm"
    >

    onsubmit="this.btnSubmit.style.display='none';document.getElementById('WaitN
    > ote').style.display='inline';return true;" ... >
    >
    > This code hides the button and shows an area that has a message.
    >
    > Works real well, except that I have an animated Gif in there and it

    doesn't
    > animate - some bug in IE related to a hidden image not animating, it works
    > with Mozilla...
    >
    > +++ Rick ---
    >
    > --
    >
    > Rick Strahl
    > West Wind Technologies
    > http://www.west-wind.com/
    > http://www.west-wind.com/blog/
    > ----------------------------------
    > Making waves on the Web
    >
    >
    > "Al Cohen" <-o-r-n-e-l-l.edu> wrote in message
    > news:D...
    > > I'm using a LinkButton to call some code, then do a redirect. The code
    > > does some queries, sends some emails, and takes a few moments before the
    > > redirect is performed.
    > >
    > > I'd like to disable my LinkButton during this period to prevent multiple
    > > submissions. (Obviously) the disabling should be done at the client
    > > side to prevent any delay. I've tried adding some javascript to
    > > LinkButton.Attributes:
    > >
    > > LinkButton1.Attributes.Add("onclick", "this.href='javascript:void(0)'"
    > > + this.GetPostBackEventReference(this.LinkButton1));
    > >
    > > but this doesn't disable the LinkButton. I also tried:
    > >
    > > LinkButton1.Attributes.Add("onclick", "this.href='javascript:void(0)'");
    > >
    > > which disables the link, but never does the postback.
    > >
    > > This seems like a very important thing to be able to do, and thus it
    > > should be reasonably easy - what am I missing?
    > >
    > > Alternatively, perhaps there's something clever that I can do on the
    > > server side to "short circuit" subsequent postbacks?
    > >
    > > Thanks,
    > >
    > > Al Cohen
    > >
    > >

    >
    >
     
    A, Dec 19, 2003
    #3
  4. Yes that is good practice. I think a more general approach should be taken
    to this sort of thing, where your code should set something right away that
    in teh DB that lets it know that the process has already started.

    But I still think from a UI perspective it's smart to use something on the
    client side to disable the button.

    --

    Rick Strahl
    West Wind Technologies
    http://www.west-wind.com/
    http://www.west-wind.com/blog/
    ----------------------------------
    Making waves on the Web


    "A" <> wrote in message
    news:...
    > Hi,
    > a solution that allways works, even if the user presses F5, or disables
    > javascript
    >
    > I normaly insert a database value (ID, Identity) in a hidden form, when

    the
    > "updating" or other stuff takes place, it first checks if the value (ID)

    is
    > in the database, if it is there updating takes place and the ID is

    deleted,
    > if it is NOT there i tell the user that their data is allready saved,
    > problerly because they hit the submit button twice...
    >
    > Regards,
    >
    > Agge
    >
    > "Rick Strahl [MVP]" <> skrev i en meddelelse
    > news:%...
    > > Hi Al,
    > >
    > > I've had that same issue. Usually you have to attach the script code to

    > the
    > > form's OnSubmit().
    > >
    > > Actually what I found is that if you disable the button that you're

    > binding
    > > events to the button's event doesn't fire because the button doesn't

    show
    > up
    > > in the post variable list. Hiding the button actually works better.
    > >
    > > I usually do this in the HTML but you should be able to do the same with
    > > attributes:
    > >
    > > <form id="frmOrderForm"
    > >

    >

    onsubmit="this.btnSubmit.style.display='none';document.getElementById('WaitN
    > > ote').style.display='inline';return true;" ... >
    > >
    > > This code hides the button and shows an area that has a message.
    > >
    > > Works real well, except that I have an animated Gif in there and it

    > doesn't
    > > animate - some bug in IE related to a hidden image not animating, it

    works
    > > with Mozilla...
    > >
    > > +++ Rick ---
    > >
    > > --
    > >
    > > Rick Strahl
    > > West Wind Technologies
    > > http://www.west-wind.com/
    > > http://www.west-wind.com/blog/
    > > ----------------------------------
    > > Making waves on the Web
    > >
    > >
    > > "Al Cohen" <-o-r-n-e-l-l.edu> wrote in message
    > > news:D...
    > > > I'm using a LinkButton to call some code, then do a redirect. The

    code
    > > > does some queries, sends some emails, and takes a few moments before

    the
    > > > redirect is performed.
    > > >
    > > > I'd like to disable my LinkButton during this period to prevent

    multiple
    > > > submissions. (Obviously) the disabling should be done at the client
    > > > side to prevent any delay. I've tried adding some javascript to
    > > > LinkButton.Attributes:
    > > >
    > > > LinkButton1.Attributes.Add("onclick", "this.href='javascript:void(0)'"
    > > > + this.GetPostBackEventReference(this.LinkButton1));
    > > >
    > > > but this doesn't disable the LinkButton. I also tried:
    > > >
    > > > LinkButton1.Attributes.Add("onclick",

    "this.href='javascript:void(0)'");
    > > >
    > > > which disables the link, but never does the postback.
    > > >
    > > > This seems like a very important thing to be able to do, and thus it
    > > > should be reasonably easy - what am I missing?
    > > >
    > > > Alternatively, perhaps there's something clever that I can do on the
    > > > server side to "short circuit" subsequent postbacks?
    > > >
    > > > Thanks,
    > > >
    > > > Al Cohen
    > > >
    > > >

    > >
    > >

    >
    >
     
    Rick Strahl [MVP], Dec 20, 2003
    #4
  5. Al Cohen

    Mr.Joe Guest

    How can I stop the linkbutton at a step, and then makes it go on to he
    next step????
     
    Mr.Joe, Dec 27, 2004
    #5
  6. I dont really understand what you are trying to ask, but as far as I can
    guess, you want to disable a link button without postback?
    Here is something I did long time ago, I put the linkbutton in a div tag and
    used javascript to show and hide it without postback..
    Does this suite ur situation?
    Hth...
    R. Thomas

    "Mr.Joe" wrote:

    > How can I stop the linkbutton at a step, and then makes it go on to he
    > next step????
    >
    >
     
    =?Utf-8?B?Ui4gVGhvbWFzLCBha2EgWHRyZW1lLk5ldA==?=, Dec 27, 2004
    #6
  7. Al Cohen

    Vikesh Arora Guest

    please elaborate your question. It is very unclear.

    "Mr.Joe" <> wrote in message
    news:...
    > How can I stop the linkbutton at a step, and then makes it go on to he
    > next step????
    >
     
    Vikesh Arora, Dec 28, 2004
    #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. Christopher D. Wiederspan

    Disable an ASP.NET form on the client before PostBack

    Christopher D. Wiederspan, Oct 24, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    800
    Alvin Bruney
    Oct 25, 2003
  2. george d lake

    how to disable a linkbutton in a repeater?

    george d lake, Oct 29, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    630
    george d lake
    Oct 29, 2003
  3. Alessandro
    Replies:
    0
    Views:
    591
    Alessandro
    Jan 12, 2004
  4. Sathyaish
    Replies:
    3
    Views:
    3,113
    Sathyaish
    Sep 8, 2005
  5. Sathyaish

    Linkbutton does not look like a linkbutton

    Sathyaish, Sep 8, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    189
    Sathyaish
    Sep 8, 2005
Loading...

Share This Page