Controls disabled with javascript not posted back to server

D

David Stahl

Good evening. I was hoping someone can help me:

I have an ASP.NET page which contains an ArrayList bound to a
DataGrid. The DataGrid displays, in columns, a few members of the
objects in this ArrayList. Each object that is displayed (ie. each row
in the DataGrid) also has an "Add" and a "Remove" button. Think
Windows Update style here.

If you click the "Add" button, it becomes Disabled and the "Remove"
button is Enabled. Click on "Remove" and it becomes Disabled and the
"Add" button is Enabled. Just like Windows Update.

I manage that Enabling/Disabling with client side Javascript. I take
the Client ID and do a "btn1.disabled = true" (or false) on the button
objects.

When a "Submit" button is pressed, the server iterates through the
rows in the DataGrid and looks for buttons that are Enabled. This is
how the server would know which buttons you've enabled or disabled.
The problem is that the state that I set via JavaScript on the client
does not seem to make it back to the server.

Initially I have all the Add buttons enabled and all the Remove
buttons disabled. If I disable all the Adds, enable all the Removes,
the server still sees them all as Disabled. Any ideas why?
 
M

Martin Dechev

Initially I have all the Add buttons enabled and all the Remove
buttons disabled. If I disable all the Adds, enable all the Removes,
the server still sees them all as Disabled. Any ideas why?

Because the browser does not post all the properties with their values of
the form controls - only the (selected) values in <input type=text |
password | hidden | radio | checkbox> and <select> are posted.

You can, for example, on the click event of the buttons on the client-side,
set the value of a <input type=hidden> field and then read this in the
server.

Hope this helps
Martin
 
D

David Stahl

Martin Dechev said:
Because the browser does not post all the properties with their values of
the form controls - only the (selected) values in <input type=text |
password | hidden | radio | checkbox> and <select> are posted.

You rock!

This was the exact problem I was having and using the hidden input was
what I needed. Actually, I wound up using an asp:TextBox with
Visible=False and Width=0, but it put me on the right track.

Now I can finally go to bed with a clear head. Thanks again!

-D
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top