答案 0 :(得分:3)
在ASPX页面中包含用户控制文件,但将其设置为不可见:
<%@ Page Language="C#" %>
<%@ Register TagName="test" TagPrefix="asp" Src="~/Test.ascx" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:test runat="server" ID="test" Visible="false" />
</form>
</body>
</html>
然后在您的页面上放置一个链接,当点击此链接时,在点击处理程序中将控件的可见性设置为true:
test.Visible = true;
以下是整个例子:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ToDD._Default" %>
<%@ Register TagName="test" TagPrefix="asp" Src="~/Test.ascx" %>
<script type="text/C#" runat="server">
protected void ShowClick(object sender, EventArgs e)
{
test.Visible = true;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:test runat="server" ID="test" Visible="false" />
<br/>
<asp:LinkButton ID="BtnShow" runat="server" Text="Show" OnClick="ShowClick" />
</div>
</form>
</body>
</html>
更新:
根据请求,这是使用javascript的相同示例:
<%@ Page Language="C#" %>
<%@ Register TagName="test" TagPrefix="asp" Src="~/Test.ascx" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
function show() {
document.getElementById('container').style.display='block';
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="container" style="display:none;">
<asp:test runat="server" ID="test" />
</div>
<br/>
<a href="#" onclick="show();">Show</a>
</div>
</form>
</body>
</html>