[英]save values from 2 or more UserControls in asp.net?
I am working in Fast Survey Project!! 我正在快速调查项目中工作!!
i have no time for design a database and all these things ,i have only one table and i have to fill the answers , i have to finish it within two days. 我没有时间设计数据库,所有这些东西,我只有一张桌子,我必须填写答案,我必须在两天内完成。
the problem is I have more than 50 questions and i divided them into 3 groups , i putted each question group in User Control, and i am trying to save the values from each user control. 问题是我有50多个问题,我将它们分为3组,将每个问题组放入“用户控件”中,并且我试图保存每个用户控件中的值。
i want to save theme temporarily after each user control and when the user reach the last user control and click finish button it should save all the answers one time . 我想在每个用户控件之后临时保存主题,并且当用户到达最后一个用户控件并单击“完成”按钮时,它应该一次保存所有答案。
so is there any idea?? 有什么想法吗? I was thinking to use something like global file !!
我正在考虑使用全局文件之类的东西!
but i don't whether it works or not but i am working on it now and i hope to find any idea from you people. 但是我不管它是否有效,但我现在正在研究它,我希望从你们那里找到任何想法。
You can temporarily save in session: 您可以临时保存会话:
var survey = new Survey();
Survey.Name = textBoxName.Text;
Session["answer"] = survey.
Then later in all forms you can use: 然后,以后可以使用所有形式使用:
var survey = Session["answer"] as Survey;
if (survey == null)
//error, redirect to start
Where Survey class is class, which contains all survey info. 其中Survey class是class,其中包含所有调查信息。
Other example, 其他例子
//Form1, question 1
List<string> survey = new List<string>();
survey.Add(textBox1.Text);
Session["survey"] = survey;
//Form2, question2
var survey = Session["survey"] as List<string>;
survey.Add(textBox1.Text);
//Form...n... final save
var survey = Session["survey"] as List<string>;
for(int i=0; i< survey.Count;i++)
{
SaveAnswer("someId", i, survey(i));
}
Here is one solution 这是一个解决方案
If you want to display a page with a group of up to three question on each page, then it becomes slightly more complicated. 如果你想用一个组的每个页面上最多三个问题来显示页面,则变得稍微复杂一些。 The question page would then be referenced with the groupID instaed.
然后将使用插入的groupID来引用问题页面。
If you only have 2 days for your implementation, then I would certainly settle for the simple one-question-per-page solution. 如果您只有2天的实施时间,那么我一定会选择简单的每页一个问题的解决方案。
This is easily solvable through UserControl public properties. 通过UserControl公共属性可以轻松解决此问题。
Here is how i would solve this: 这是我要解决的方法:
// this dictionary will eventually be serialized and kept in session
// throughout the whole Q&A session
var questionsAndAnswers = new Dictionary();
foreach(var control in MyUserControls)
{
questionsAndAnswers.Add(control.Question, control.Answer);
}
this.Session["q&a"] = questionsAndAnswers;
Something like that should do the work. 像这样的事情应该做的工作。
The main point here is the emphasis on getting the needed information through exposed properties from your child controls (the same concept can be applied on any parent/child level in your code). 这里的重点是强调通过子控件的公开属性获取所需的信息(相同的概念可以应用于代码中的任何父/子级别)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.