简体   繁体   中英

Handling variable number of fields in ASP.NET WebForms Page

I wanted 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM