I have a control that is loaded dynamically and contains a repeater amongst other items such as a group of text boxes.
The control is used for address verification.
The process is:
- control displays.
- User enters the address info.
- page posts back and the control validates the address info against a web service.
- If the address isn’t 100%, it displays a list of potential matches. <- this occurs in a repeater. In other words, it is databound in code.
- The user checks a box next to the one they want to accept.
- page posts back
So far, 1 – 6 work. The problem is that when the page posts back, there are no repeater items.
How can I get the repeater to load it’s items without having to run another databind() operation?
Failing that, how can I run the databind() effectively? In other words, I don’t have the controls street/city/state/zip values during the oninit. So, how can I reapply the viewstate changes?
Most controls are rendered as HTML form elements like
<input type="text" name="myId" id="myId/>.Part of Web Forms is really just a wrapper around all of this.
Whenever you need to get at the raw values, you can just look in the Request.Forms collection for any control values that are posted back with the name of the control you are looking for (which will usually be made up of the unique id that asp.net generates for uniqueness of controls, and your name).
This is exactly what you did – you went through the Forms collection looking at the raw form values that were POSTed to the server. It’s also what you often do when you implement the IPostBackDataHandler interface when creating your own controls – you scoop the value out of Request.Forms.
The annoying thing with checkboxes is that with “standard” HTML they only get submitted if they are ticked.