disabling a button server-side then re-enabling client-side breaks button postback
Posted on
16th Feb 2014 07:03 pm by
admin
I have a tabbed container and a button (not in the container) on a page. If the first tab is selected, I want the button enabled. If the second is selected, I want the button disabled. I have created this functionaliity, but I have encountered some odd behavior.
Switching tabs is handled client-side, and therefore, when the tabs are switched, I use something like the following to enable/disable the button client-side based on which tab is selected:view plaincopy to clipboardprint?var saveButton = document.getElementById("<%= btnSave.ClientID %>") if (saveButton) { saveButton.disabled=false; if mytab=="Tab2") { saveButton.disabled=true; } } var saveButton = document.getElementById("<%= btnSave.ClientID %>")
if (saveButton) {
saveButton.disabled=false;
if mytab=="Tab2") {
saveButton.disabled=true;
}
}view plaincopy to clipboardprint? view plaincopy to clipboardprint?This works great but the first problem I run into is, if a control on the second tab (the button is disalbed when this tab is selected) causes a postback, then after the postback the button's state is returned to enabled. This sort of makes sense since the page lifecycle, at this point, knows nothing about what the button state should be. I decided the solution to this would be to check what the current tab is during page load, and if it is the second tab, set the button enabled property to false. In this way, when a postback occurs on the second tab, the button remains disabled. Well, this works to a charm, but I encountered a bizzare side-effect. This works great but the first problem I run into is, if a control on the second tab (the button is disalbed when this tab is selected) causes a postback, then after the postback the button's state is returned to enabled. This sort of makes sense since the page lifecycle, at this point, knows nothing about what the button state should be. I decided the solution to this would be to check what the current tab is during page load, and if it is the second tab, set the button enabled property to false. In this way, when a postback occurs on the second tab, the button remains disabled. Well, this works to a charm, but I encountered a bizzare side-effect.view plaincopy to clipboardprint? view plaincopy to clipboardprint?On the second tab, a postback is caused. The button remains disabled as it should be. I then swith tabs. The client-side code goes into effect and the button client-side disabled property is set to false. However the strange thing is, now the button doesn't work. Clicking on it does not cause a postback and doesn't really do anything. It seems that setting the button enabled property to false and then true server-side, somehow doesn't jive with setting it's disabled property to false on the client. On the second tab, a postback is caused. The button remains disabled as it should be. I then swith tabs. The client-side code goes into effect and the button client-side disabled property is set to false. However the strange thing is, now the button doesn't work. Clicking on it does not cause a postback and doesn't really do anything. It seems that setting the button enabled property to false and then true server-side, somehow doesn't jive with setting it's disabled property to false on the client.view plaincopy to clipboardprint? view plaincopy to clipboardprint?anyone have an idea what is going on?
Your Answer:
Login to answer
96
11
Other forums
Breaking results into week blocks
I have a set of dates (and times), which are returned from a mySQL query.
These usually span
jquery validation in codeIgniter
hai i need to add client side validation to my fiels which are selected in a forloop.the fields are
count only commas outside parenteses
I have a sql table containing
id - query - query name
the first page contains a drop down men
True way to see if action was successful?
If this is a good way to see if action was successful to continue:
Code: function changeGa
php problem?
I don't think I'm stupid, but maybe I am.
I am working on a sit for a friend I am try to put
Please help - should be a simple fix.. driving me nuts
Everything seemed to be working fine. I have a table, it alphabetically lists a bunch of cities and
Help with form post data and arrays
Hi all,
I am new to this forum... It has been awhile since i have worked with arrays, and i a
Advice on how to delete a mysql row using my form
Hi,
I am very new to php and am struggling to work out how to delete a portfolio item (a row
a multi dimensional array with for each
hi, I have been asked to write an array, I have Zone 2,3,4,5,6,7,8 each zone has 3 sections of weigh
Random Number Generation And Probability
Hello, I am working on a function which has to insert data into a SQL table.
we have to suppl