开发者

asp.net render partial -render ascx page tnto aspx page [closed]

开发者 https://www.devze.com 2022-12-13 01:41 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can b开发者_运维问答e reopened, visit the help center. Closed 10 years ago.

hey..i am new to asp.net and i want to know how to render a partial page (.ascx) into .aspx page on a link click


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消