我目前遇到的问题是我的按钮和其他控件在更改视图后没有出现在页面上。该程序设置如下:
我让程序切换到正确的视图,但是当它切换按钮时,文本框和下拉列表都会消失。这是在asp.net中更改视图背景的正确方法吗?
<asp:MultiView ID="mtvNumber" runat="server" ActiveViewIndex ="-1">
<asp:View ID="View1" runat="server">
<div style='position:absolute;z-index:0;left:0;top:0;width:100%;height:100%'>
<img src='Images/Patriots.jpg' style='width:100%;height:100%' alt='[]' />
</div>
<p>Hello from view1</p>
</asp:View>
我不确定这是否是将图像设置为背景的正确方法。如果有其他人有其他方式引入图片,请告诉我!
ASP.Net代码
<div>
<form id="formViews" runat="server">
<asp:TextBox ID="tbxNumber" runat="server"></asp:TextBox>
<asp:Button ID="btnNumber" runat="server" Text="Button" OnClick="btnNumber_Click" />
<asp:DropDownList ID="ddlViews" runat="server" OnSelectedIndexChanged="ddlViews_SelectedIndexChanged"></asp:DropDownList>
<asp:Button ID="BtnChangeView" runat="server" Text="Change View" OnClick="BtnChangeView_Click" />
<asp:MultiView ID="mtvNumber" runat="server" ActiveViewIndex ="-1">
<asp:View ID="View1" runat="server">
<div style='position:absolute;z-index:0;left:0;top:0;width:100%;height:100%'>
<img src='Images/Patriots.jpg' style='width:100%;height:100%' alt='[]' />
</div>
<p>Hello from view1</p>
</asp:View>
<asp:View ID="View2" runat="server">
<div style='position:absolute;z-index:0;left:0;top:0;width:100%;height:100%'>
<img src='Images/patriots2.jpg' style='width:100%;height:100%' alt='[]' />
</div>
</asp:View>
C#代码
protected void BtnChangeView_Click(object sender, EventArgs e)
{
// string used to check input.
string viewChecker = ddlViews.SelectedValue.ToString();
// if view1 is selected, switch to view1
if (viewChecker == "view1")
{
mtvNumber.ActiveViewIndex = 0;
Response.Write("made it to the first view");
BtnChangeView.Visible = true;
btnNumber.Visible = true;
// if view2 is selected, switch to view2
}
else if (viewChecker == "view2")
{
mtvNumber.ActiveViewIndex = 1;
Response.Write("made it to the second view");
}
// if view3 is selected, switch to view3
else if (viewChecker == "view3")
{
mtvNumber.ActiveViewIndex = 2;
Response.Write("made it to the third view");
}
答案 0 :(得分:0)
也许您对图像应用的样式?试试这个,看看视图是否发生变化,其他控件是否仍在那里。
<div>
<form id="formViews" runat="server">
<asp:TextBox ID="tbxNumber" runat="server"></asp:TextBox>
<asp:Button ID="btnNumber" runat="server" Text="Button" OnClick="btnNumber_Click" />
<asp:DropDownList ID="ddlViews" runat="server" OnSelectedIndexChanged="ddlViews_SelectedIndexChanged"></asp:DropDownList>
<asp:Button ID="BtnChangeView" runat="server" Text="Change View" OnClick="BtnChangeView_Click" />
<asp:MultiView ID="mtvNumber" runat="server" ActiveViewIndex ="-1">
<asp:View ID="View1" runat="server">
<div>
<h2>Patriots View 1</h2>
<img src='Images/Patriots.jpg' style='width:100%;height:100%' alt='[]' />
</div>
<p>Hello from view1</p>
</asp:View>
<asp:View ID="View2" runat="server">
<div>
<h2>Patriots View 2</h2>
<img src='Images/patriots2.jpg' style='width:100%;height:100%' alt='[]' />
</div>
</asp:View>