我创建了for(int i = 0; i < 5; i++)
{
lblInfo.InnerText = artist;
string name = (stuff.topalbums.album[i].name.ToString());
string playcount = stuff.topalbums.album[i].playcount.ToString();
string image = stuff.topalbums.album[i].image[2].text.ToString();
//System.Web.UI.WebControls.Image img = (System.Web.UI.WebControls.Image)e.Row.Cells[2].FindControl("Image1");
//img.ImageUrl = image;
dt.Rows.Add(artist, name, playcount, image);
}
和.Master, .aspx
页面。我想点击.master页面上的按钮调用.ascx页面。如果未单击该按钮,则不应显示.ascx。
目前,.ascx
页面,.ascx页面正在调用,因为我使用了Onload
。但我想点击按钮不在页面加载。
非常感谢任何帮助。提前谢谢。
我的母版页看起来像这样:
<uc1:Account runat="server" ID="Account" />
我的用户控件如下所示:
<%@ Master Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Staff.master.cs" Inherits="Admin_Staff" %>
<%@ Register Src="~/Controls/Account.ascx" TagPrefix="uc1" TagName="Account" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<h4>Account</h4>
<span class="input-group-btn">
<input type="text" class=" search-query form-control" placeholder="Search" />
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</span>
<div class="col-lg-9">
<uc1:Account runat="server" ID="Account" />
</div>
</asp:Content>
我的<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Acc.ascx.cs" Inherits="Admin_Controls_Account" %>
<asp:panel id="pnlAcc" runat="server">
<section id="AccForm">
<asp:PlaceHolder runat="server" ID="PlaceHolder1" Visible="false">
</asp:PlaceHolder>
<div class="form-group">
<asp:Label runat="server" CssClass="col-md-2 control-label">Country: </asp:Label>
<div class="col-md-10">
<asp:Label runat="server" CssClass="col-md control-label" >New Zealand</asp:Label>
</div>
</div>
</section>
</asp:panel>
页面
.aspx
答案 0 :(得分:0)
简单的方法是使控件在母版页上不可见。
<uc1:Account runat="server" ID="Account" Visible="False" />
点击按钮后显示。
答案 1 :(得分:0)
您可以将控件的可见性设置为false,并在按钮单击
上更改它<uc1:Account runat="server" ID="Account" Visible="false" />
然后点击按钮
protected void Button1_Click(object sender, EventArgs e)
{
Account.Visible = true;
}
或者您可以动态添加控件
protected void Button1_Click(object sender, EventArgs e)
{
Admin_Controls_Account account = (Admin_Controls_Account)LoadControl("~/Controls/Account.ascx");
PlaceHolder1.Controls.Add(account);
}
请注意,对于最后一个选项,每次有PostBack时都必须重新加载控件,因此您必须自己存储Visibility并在每次加载页面时重新创建控件。