关闭

[ASP.NET2.0]动态加载用户控件

433人阅读 评论(0) 收藏 举报



uc.ascx
===============================================================
<%@ Control Language="C#" ClassName="MyLogin" %>

<script runat="server">

    protected void Button1_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "aaaaaaaaaaaaaa";
    }

</script>

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>


test.aspx
===============================================================

<%@ Page Language="C#" %>

<%@ Reference Control="~/MyLogin.ascx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        System.Web.UI.Control u = (MyLogin)Page.LoadControl("~/MyLogin.ascx");
      
 PlaceHolder1.Controls.Add(u);
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>用户自定义控件动态加载</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
    </div>
       
    </form>
</body>
</html>

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:77498次
    • 积分:1304
    • 等级:
    • 排名:千里之外
    • 原创:43篇
    • 转载:29篇
    • 译文:0篇
    • 评论:16条
    最新评论