ASP.NET: adding controls client-side

前端 未结 6 805
我在风中等你
我在风中等你 2020-12-18 05:25

If I have a page with a form (imagine a simple one with just TextBoxes and a submit button) and I want to allow the user to dynamiccally add more TextBoxes to the form via j

6条回答
  •  温柔的废话
    2020-12-18 06:06

    In webforms you won't have a lot of choices if you expect the values to postback and be able to access them in typical fashion. What I would suggest is that you use an Ajax UpdatePanel to allow the controls to be registered at the appropriate point of the page lifecycle (before onLoad), this will also make a difference on whether or not you need the boxes to persist across postbacks. The JS methods involved in the other 2 answers will not persist the textboxes through a postback.

    MVC gives you more leeway, since there isn't that crazy page lifecycle, control registration, viewstate, etc to get in your way.

    So the big question is, which model/framework for ASP.Net are you using?


    Since you are indeed using webforms, I really strongly suggest you go with updatepanels if they'll work for you. it will permit you to add controls in such a way that wont get in the way of eventvalidation, etc.

提交回复
热议问题