0

ちょっと..私はasp.netを初めて使用し、リンクをクリックして部分ページ(.ascx)を.aspxページにレンダリングする方法を知りたいです

4

1 に答える 1

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>
于 2009-11-26T07:16:45.077 に答える