建议:坚持用户输入动态创建的用户控件 [英] Advice: Persisting User Input for dynamically created user controls

查看:139
本文介绍了建议:坚持用户输入动态创建的用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.Net创建用户向导。其中一个我包括额外的步骤是收集联系人信息连接的客户可能有同胞的同事,以便该帐户被配置可以批量为他们创造登录为好。我使用的ContactPerson用户包括对关键信息的几个文本框(姓名,出生日期,公司名称,地址和状态)。

I have a ASP.Net create user wizard. One of the additional steps I included is to gather contact information for connections the customer may have to fellow co-workers so the account being configured can batch create logins for them as well. The user I use for ContactPerson consist of several text boxes for key info (Name, DoB, Company Name, Address and State).

我用一个简单的按钮来调用它创建用于RadPanelItems正确的嵌套结构AddContacts方法。当我添加它正常工作的第一项,第二个,虽然抹了第一回发经过和缺乏数据持久化。

I use a simple button to invoke the AddContacts method which creates the proper nesting structure used for RadPanelItems. As soon as I add the first item it works fine, the second one though wipes out the first via postback and lack of data persistence.

这个用户控件映射到实体EF4,特别是页面有一个名为List ContactList成员。我想问问什么是最好的办法,我坚持我从previous接触云集重新新增我的用户控件一起我的实体数据(有数据说的)回表后遇到回来的时候?

This user control maps to an EF4 Entity, specifically the page has a member called List ContactList. I wanted to ask what would be the best way for me to persist my Entity data I gathered from the previous contact along with re-adding my user control (with said data) back to the form when a post back is encountered?

我打开的建议,我在寻找一个最佳实践的解决方案(S)。先谢谢了。

I am open to suggestions and I am looking for a best practice solution(s). Thanks in advance.

推荐答案

直到你坚持你的数据,你可以使用HttpContext.Current。会议对象来存储这些信息。会话(存储在服务器上)是较大的数据更好,在的ViewState (保存在网页上的隐藏字段),可用于较小的数据,因为它是来回发送的每一个请求,并迅速炸毁页面大小。为了讨论参见<一个href=\"http://stackoverflow.com/questions/2883149/viewstate-vs-session-maintaining-object-through-page-lifecycle\">ViewState VS会话...通过页面生命周期维护对象或的http:// msdn.microsoft.com/en-us/library/ms972976.aspx

Until you persist you data, you can use the HttpContext.Current.Session object to store this info. The Session (stored on the server) is better for larger data, the ViewState (stored in a hidden field on the page) can be used for smaller data as it is sent back and forth every request and quickly blows up the page size. For discussion see ViewState Vs Session ... maintaining object through page lifecycle or http://msdn.microsoft.com/en-us/library/ms972976.aspx

Annother选项(的不是一个好您的具体情况的)可以像具有优势,你可以复制粘贴URL到电子邮件ID或主键非常小的数据QueryParameters,仍然有信息。看的http://www.$c$cproject.com/Articles/5876/Passing-variables-between-pages-using-QueryString

Annother option (not a good one for your situation) is QueryParameters for very small data like IDs or primary Keys having the advantage that you can copy paste the url to an email and still have the info. see http://www.codeproject.com/Articles/5876/Passing-variables-between-pages-using-QueryString

所以,回到你的问题:对于每一个新的联系人添加,执行这样的事情,直到你终于坚持你的数据

So back to your issue: For every new contact you add, perform something like this until you finally persist your data.

var contacts = new List<EF4Entity>()
if (Session["Contacts"] != null){
  contacts = Session["Contacts"] as List<EF4Entity>
}

var newContact = new EF4Entity()
//fill your new contact here
contacts.Add(newContact)

//bind your RadPanelItems here

//store it to the session
Session["Contacts"] = contacts

这篇关于建议:坚持用户输入动态创建的用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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