• 动态添加用户控件实例


    WebUserControl.ascx:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

    WebUserControl.ascx.cs:

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class WebUserControl : System.Web.UI.UserControl
    {
      string a = "ok";
      public string A
      {
        set {
          a = value;
        }
        get
        {
          return a;
        }
      }
        protected void Page_Load(object sender, EventArgs e)
        {
          TextBox1.Text = A;
        }
     
    }


    调用:

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

    <!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 )
      {
        WebUserControl a = (WebUserControl)Page.LoadControl("~/WebUserControl.ascx");
        a.A = "xxx";
        form1.Controls.Add(a);
      }
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
      
        </form>
    </body>
    </html>

  • 相关阅读:
    Mysql 库表
    Mysql (二)
    SQLAlchemy
    Mysql 测试题
    jquery
    抽屉 演示
    前端项目
    JavaScript
    Html Css  练习
    Pandas之DataFrame——Part 3
  • 原文地址:https://www.cnblogs.com/yibinboy/p/497854.html
Copyright © 2020-2023  润新知