
click to enlarge
Double click on one of the “Submit” button to open the Visual Basic code window on the file named “CheckBoxExample.aspx.vb” to edit the code. Use the following example to code for the first box and then repeat for each one, substituting the relevant ID:
If WordPub.Checked then
Selected.Text &= “ You use Word Processing software.”
End if
The reason for using “&=” is to retain the last variable and concatenate it with the next so that if the user selects more than one, all will be displayed. The purpose of the Label control is to demonstrate the result. Normally you would use the results in some other way.
There is just one other piece of code you need to add to the Submit button. Even though you cleared the text property of the “Selected” label at design, when the page runs in a browser, the preceding results would appear in subsequent refreshes. One way to handle this is insert a “Clear” command button and associate code with it to reset the text values to nothing when all CheckBoxes are cleared. A simpler way is to put one additional line at the beginning of the code lines you just created. Add this: “Selected.Text = "" which will set the text to nothing.
Edit attributes of each ASP.Net CheckBox and Button using the Properties to set font, size, border color and style as well as other formatting options. The final image is a live Web shot to show overdone formatting for illustrative reasons.