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

G

Guest

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
 
B

bruce barker

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 said:
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.
 
Joined
May 27, 2008
Messages
1
Reaction score
0
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;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top