回发后的多视图控件
我正在尝试使用多视图控件。我首先创建一些视图并在 preinit 事件中添加一些标签。将它们添加到 (!isPostBack) 场景中的多视图中。 我想使用“下一个”和“上一个”按钮在视图之间导航。这就是我所做的:
protected void Page_PreInit(object sender, EventArgs e)
{
if (IsPostBack)
{
MultiView1 = (MultiView)Session["multi"];
}
else
{
View view1 = new View();
View view2 = new View();
View view3 = new View();
Label l1 = new Label(); l1.Text = "1";
Label l2 = new Label(); l2.Text = "2";
Label l3 = new Label(); l3.Text = "3";
view1.Controls.Add(l1);
view2.Controls.Add(l2);
view3.Controls.Add(l3);
MultiView1.Views.Add(view1);
MultiView1.Views.Add(view2);
MultiView1.Views.Add(view3);
MultiView1.ActiveViewIndex = 0;
Session["multi"] = MultiView1;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex++;
}
protected void Button1_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex--;
}
这将不起作用,就好像多视图不保存其内容一样,并且不允许我将 activeviewindex 更改为大于 0 的值。我如何修改它以便我可以更改活动视图索引?
I'm trying to use a multiview control. I'm first creating some views and add to those some labels in the preinit event. Add those to the multiview in the (!isPostBack) scenario.
I want to navigate between Views using 'next' and 'previous' buttons. This is what I've done:
protected void Page_PreInit(object sender, EventArgs e)
{
if (IsPostBack)
{
MultiView1 = (MultiView)Session["multi"];
}
else
{
View view1 = new View();
View view2 = new View();
View view3 = new View();
Label l1 = new Label(); l1.Text = "1";
Label l2 = new Label(); l2.Text = "2";
Label l3 = new Label(); l3.Text = "3";
view1.Controls.Add(l1);
view2.Controls.Add(l2);
view3.Controls.Add(l3);
MultiView1.Views.Add(view1);
MultiView1.Views.Add(view2);
MultiView1.Views.Add(view3);
MultiView1.ActiveViewIndex = 0;
Session["multi"] = MultiView1;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex++;
}
protected void Button1_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex--;
}
This will not work as if the multiview does not save it's content and won't allow me to change activeviewindex to a value greater than 0. How can i modify it such that i'll be allowed to change activeviewindex?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您每次都需要重新创建所有动态控件。如果将代码更改为以下内容,按钮应该可以工作:
我将代码移至 OnInit,因为由于某种原因,MultiView 尚未在 Pre_Init 上初始化。
You need to recreate all dynamic controls each time. If you change the code to the following the buttons should work:
I moved the code to OnInit because for some reason the MultiView was not yet initialized on Pre_Init.