English 中文(简体)
asp.net render partial -render ascx page tnto aspx page [closed]
原标题:
问题回答

Include the user control file in your ASPX page but set it to invisible:

<%@ 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>

Then put a link on your page and when this link is clicked set the visibility of the control to true in the click handler:

test.Visible = true;

And here s the whole example:

<%@ 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>

UPDATE:

As requested here s the same example using 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>




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签