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
Add a ment  | 

4 Answers 4

Reset to default 2

See 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