简体   繁体   English

回发后如何保留动态创建的控件

[英]How to retain dynamically created control after postback

I'm working on a quiz web app in ASP.Net C#. 我正在使用ASP.Net C#开发测验Web应用程序。 In the editquiz page, it allows user to add and remove questions from the quiz using JS. 在editquiz页面中,它允许用户使用JS从测验中添加和删除问题。 Once user have saved the changes, question data will be passed from client to server for validation before storing in db. 用户保存更改后,问题数据将从客户端传递到服务器以进行验证,然后再存储在数据库中。 If the string fails validation, it will alert the user however, the question controls constructed previously will be destroyed upon postback. 如果字符串验证失败,它将警告用户,但是先前构造的问题控件将在回发时销毁。

How can I retain the question controls and their values apart from reconstructing them based on the posted JSON string? 除了根据发布的JSON字符串重建问题控件外,如何保留问题控件及其值?

Put that save or submit button inside scriptmanager of ajax controls. 将保存或提交按钮放在ajax控件的scriptmanager中。

Add scriptmanager tag next to your form tag, 在表单标签旁边添加scriptmanager标签,

<form id="form1" runat="server">
 <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

and

 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
   <ContentTemplate >
        your button of save or submit,
   </ContentTemplate>
 </asp:UpdatePanel>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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