I'm an extreme newbie, so please be nice.
I'm having issues in getting radio buttons and checkboxes on a form to return the values "Yes" or "No".
So far, the radio buttions are returning "True" or "False", which is a start (but I want it to be "Yes" or "No").
The code for the radio buttons on the "aspx" file is the following:
And the code for the radio buttons on the "aspx.cs" file is the following:
MMsg.Body += "One Central Purchasing Location?: " + rblCentralPurchasing.Text + "\r\n";
The checkboxes just plain aren't working. So far they're returning the text that's written after the checkbox whether the checkbox is checked or not.
The code for the checkboxes on the "aspx" file is the following:
And the code for the checkboxes on the "aspx.cs" file is the following:
MMsg.Body += "May we send updates and promotions using e-mail?: " + chkEmail.Text + "\r\n";
Your help will be GREATLY appreciated!!
Thanks,
Blastbum :)
Scott LyslePosted Oct 24, 2006, 2:38 PM
Part of the trouble is that fact that, which the checkbox, you are reading the text property which has no relationship to the state of the control. The 'checked' property is what you want to evaluate in order to determine whether or not the item is checked. The text is just the verbiage that is appended to the checkbox to describe what the checkbox is meant to indicate when checked or unchecked.
Since you are using server side controls, the easiest way to process the meaning of the radiobuttons and the checkboxes would be through the code behind page. Radio buttons and checkboxes both have a property called 'checked' and both have and event called CheckedChanged. What I would recommend is using writing an event handler for the CheckedChanged event and within the body of that handler, use an interpretation of the checked state to determine the whether or not want a yes or a no, or some other value from it. If if you have a collection of items (radio buttons and checkboxes) to evaluate upon a form submittal, you can, in the code behind page, look at the checked value of each of the items of interest and determing how to process your submittal based upon the state of each of those controls.
If you are using multiple radiobuttons and checkboxes, you may wish to look at using the radiobutton list and checkbox list control options.
If you need a demo, send me an email address and I will write something to show you how this works and send it to you.
Hope it helps,
Scott Lysle
([email protected])