qghboy.Net专栏

用代码书写人生,用软件改变生活

[ASP.NET2.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>

阅读更多
个人分类: (1)DotNet (3)Web
上一篇[ASP.NET2.0]Global.asax实现在线人数统计和站点访问总量
下一篇[Web]滚动控件使用
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭