I w开发者_JAVA百科anted to gather some methods on how to add a variable number of fields to my form (with Add New and Remove buttons). I know that ASP.NET MVC has easy methods, but I'm unable to find any easy methods for WebForms.
Here's what I've used so far:
- Adding a new UserControl to a PlaceHolder on PostBack (I've had to fiddle with ViewState to make this work correctly, huge pain)
- Adding a new row to a grid and having a template field in a grid (works decently but kind of awkward)
- Actually having several fields on the form by default and hiding/showing them dynamically (fairly easy but you have a set number of fields.)
Any other methods? Thanks!
You can add them with Javascript and on postback get their value with
Request.Params["ControlId_1"]
You just need a convention on the ControlId naming.
精彩评论