动态创建控件并保存整个回传的控制值 - ASP.Net C# [英] Dynamically Create controls and save the controls values across postback - ASP.Net C#

查看:119
本文介绍了动态创建控件并保存整个回传的控制值 - ASP.Net C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑这一点 -

我允许最终用户通过获得一些细节的ASP.Net页面动态创建一个标签控件。对于每一个选项卡中添加我得到的一些设置 -

I allow the end user to create a tab control dynamically in an ASP.Net page by getting some details. For each and every tab added I get some settings -


  1. 标签标题

  2. 标签内容

  3. 标签页脚链接

所以我把这些细节每一个标签。向用户提供一个按钮添加标签更多一个标签。所以,我需要在页面中添加一个标签设置面板以获得选项卡设置。但这样做,我失去了在pviously创建的动态选项卡设置面板中的$ P $输入的值。用户可以添加尽可能多的标签和为每个选项卡中输入设置。最后,当他们保存它,我建(根据自己的设置和内容)选项卡控制和I呈现控件。

So I get these details for each and every tab. The user is provided with a button 'Add Tab' to more one more tab. So I need to add one more tab settings panel in the page to get the tab settings. But doing so, I lose the values entered in the previously created dynamic tab settings panel. The user can add as many tabs and enter settings for each and every tab. Finally when they save it I build the tab control (based on their settings and content) and I render the control.

由于控制是动态的,我能够在两种选择中的事情 -

Since the controls are dynamic, I'm able to thing of two options -


  1. 重新创建previously创建N - 1选项卡设置面板,同时增加了第n个标签。所以在整个的每一个回传我需要重新创建每个选项卡中的设置面板。但我不知道如何坚持在这种情况下的值。

  2. 用简单的HTML控件添加在客户端的设置面板,并在页面卸载解析控制 - >解析设置 - >将它保存在一个隐藏字段 - >获取它在服务器端。在这种情况下,我失去了所有,我需要写的控制验证脚本服务器端功能。

关于如何更好地做到这一点任何见解?

Any insights on how better to do this?

推荐答案

我想补充的控制服务器端,只记得你需要的重新创建每个回传的所有控件

I would add the controls server-side, just remember that you need to re-create all controls on every postback

您可以节省您需要在视图状态中创建然后生成你的控件树中的的CreateChildControls

You could save your details of any controls that need to be created in viewstate then build your control tree from that in CreateChildControls

这篇关于动态创建控件并保存整个回传的控制值 - ASP.Net C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆