การแทรก web user control ผ่านการเขียนโค้ด

public partial class WebForm1 : System.Web.UI.Page

    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Control objCtr1;
            objCtr1 = LoadControl("WebUserControl1.ascx");
            this.PlaceHolder1.Controls.Add(objCtr1);
        }
    }

WebPage1.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebAppTest.TestModule.WebForm1" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div id="TestModule1">

<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>

    </div>

    </form>

</body>

</html>

0 comments: (+add yours?)

Post a Comment