admin管理员组文章数量:1425868
I am adding HTML input controls on the page dynamically via a "add text box" button but after post back eventually they are being washed away. Is there an easy and good practice which can help me keep the controls and their values after page post back.
Thanks.
Edit :
- I am using Javascript to create dynamic controls on the page
- I am not dealing with File Uploads, just creating custom field things.
I think I need to override SaveViewState and LoadViewState events to keep my controls in the ViewState.
I am adding HTML input controls on the page dynamically via a "add text box" button but after post back eventually they are being washed away. Is there an easy and good practice which can help me keep the controls and their values after page post back.
Thanks.
Edit :
- I am using Javascript to create dynamic controls on the page
- I am not dealing with File Uploads, just creating custom field things.
I think I need to override SaveViewState and LoadViewState events to keep my controls in the ViewState.
Share Improve this question edited Jan 10, 2010 at 8:25 Tarik asked Jan 9, 2010 at 5:16 TarikTarik 81.9k86 gold badges242 silver badges351 bronze badges 2- Do you add the input controls using javascript or C# ? – Madi D. Commented Jan 9, 2010 at 5:27
- @Madi : I am using Javascript to add controls on the page. – Tarik Commented Jan 9, 2010 at 5:37
4 Answers
Reset to default 2See followings:
http://urenjoy.blogspot./2009/02/add-dynamic-buttons-and-handle-click.html
You need to override SaveViewState and LoadViewState methods to save after postback, See following sample
http://urenjoy.blogspot./2009/03/create-dynamic-dropdownlists-in-aspnet.html
and To retrieve value see following example:
http://urenjoy.blogspot./2009/02/retrieve-value-of-dynamic-controls-in.html
Keep the page! Use ajax to post the data, and a flash uploader if you are dealing with file uploads. Then the page never refreshes, and there is a lot less code to re-do the dynamically created controls.
since you will receive them on post back, could you not recreate them dynamically at server-side ?
If the controls differ from postback to postbck depending on what the user enters then you can try storing the html ito a seperate class where you will have static properties like
public static string WriteHTMLSubmit = ""
If not then hard code them in code behind, this being the bes practice...
if(page.isPostBack){<write contrls>}
本文标签: cKeep programmatically created html controls after postbackStack Overflow
版权声明:本文标题:c# - Keep programmatically created html controls after postback - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745459532a2659258.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论