Button disabled and re-enabled in client side not firing server-side click event.

Discussion in 'ASP .Net' started by =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=, Jun 2, 2004.

  1. Hi all

    I got a strange problem
    In my webform, I have a server-side Button "btnDisable" to save some data and enable or disable all other fields in this form based on the data.
    The logic is: on server click event, save data, write a client-side script to set 'ynDisable' to true or false, and then use general client-side code in window's onload event to disable all fields. The code is
    function disableFields(

    with (window.document

    var iDocLen = all.length
    for(var i = 0; i < iDocLen; i++

    all(i).disabled = true



    This code also disabled the Button "btnDisable". So I add one line of code to enable it
    if (yndisable == true

    disableFields()
    window.document.getElementbyId("btnDisable").disabled = false
    window.document.getElementbyId("btnDisable").value = "Enable"


    Then the strangest thing happens. The server-side click event of btnDisable is not fired after clicking
    In testing, if I don't call disableFields function, the event is fired
    Or if I change to the following code
    window.document.getElementbyId("btnDisable").disabled = true
    window.document.getElementbyId("btnDisable").disabled = false
    The click event is also fired
    Do somebody know why

    Bin Song, MCP
    =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=, Jun 2, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=

    bruce barker Guest

    browsers do not postback any values for disabled input controls. if you
    disable the button, its value will not be posted, and the server has no way
    of knowing the button was clicked.

    -- bruce (sqlwork.com)



    "Bin Song, MCP" <> wrote in message
    news:...
    > Hi all,
    >
    > I got a strange problem.
    > In my webform, I have a server-side Button "btnDisable" to save some data

    and enable or disable all other fields in this form based on the data.
    > The logic is: on server click event, save data, write a client-side script

    to set 'ynDisable' to true or false, and then use general client-side code
    in window's onload event to disable all fields. The code is:
    > function disableFields()
    > {
    > with (window.document)
    > {
    > var iDocLen = all.length;
    > for(var i = 0; i < iDocLen; i++)
    > {
    > all(i).disabled = true;
    > }
    > }
    > }
    > This code also disabled the Button "btnDisable". So I add one line of code

    to enable it.
    > if (yndisable == true)
    > {
    > disableFields();
    > window.document.getElementbyId("btnDisable").disabled = false;
    > window.document.getElementbyId("btnDisable").value = "Enable";
    > }
    >
    > Then the strangest thing happens. The server-side click event of

    btnDisable is not fired after clicking.
    > In testing, if I don't call disableFields function, the event is fired.
    > Or if I change to the following code:
    > window.document.getElementbyId("btnDisable").disabled = true;
    > window.document.getElementbyId("btnDisable").disabled = false;
    > The click event is also fired.
    > Do somebody know why?
    >
    > Bin Song, MCP
    bruce barker, Jun 2, 2004
    #2
    1. Advertising

  3. =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=

    rick74

    Joined:
    May 27, 2008
    Messages:
    1
    Location:
    Banglore, India
    Instead of disabling the button, you could make it as invisible. So that the server post back will continue.

    If you realy need to show as the button as disabled, there is a work around. keep a dummy button near to your submit button, and show it as disabled while you hide your original submit button.

    var submitcount=0;
    function AllowOneClick(id)
    {
    if (typeof(Page_ClientValidate)=='function')
    {
    if (Page_ClientValidate() == true)
    {
    return checkSubmit(id);
    }
    else
    {
    return true;
    }
    }
    else
    {
    return checkSubmit(id);
    }
    }

    function checkSubmit(id)
    {
    var oButton = document.getElementById(id);
    if (submitcount == 0)
    {
    if(oButton != null)
    {
    var text = oButton.value;
    oButton.value = "";
    oButton.style.visibility = 'hidden';
    oButton.style.width = '0px';
    var oDummy = document.getElementById("btnDummy");
    oDummy.style.visibility = 'visible';
    oDummy.value = text;
    }
    submitcount++; return true;
    }
    else
    {
    if(oButton != null)
    {
    oButton.value = "Please wait...";
    oButton.disabled = true;
    }
    return false;
    }
    }
    rick74, May 27, 2008
    #3
    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:
    830
    Purvi T
    Oct 19, 2004
  2. UJ
    Replies:
    3
    Views:
    671
    Eliyahu Goldin
    Jul 20, 2005
  3. Amy
    Replies:
    0
    Views:
    976
  4. Aymer
    Replies:
    1
    Views:
    387
    Alvin Bruney
    Sep 19, 2003
  5. JohnH.
    Replies:
    3
    Views:
    1,313
    Ken Cox [Microsoft MVP]
    Mar 30, 2005
Loading...

Share This Page