zoukankan      html  css  js  c++  java
  • C#中动态创建控件示例介绍

    代码如下:

    1 private TextBox Txt;      
     2      
     3     protected void Page_Load(object sender, EventArgs e)      
     4      
     5     {      
     6      
     7         Create();      
     8      
     9     }      
    10      
    11     private void Create()      
    12      
    13     {      
    14      
    15         Button Btn = new Button();      
    16      
    17         Btn.ID = "MyBtn";      
    18      
    19         Btn.Text = "显示";      
    20      
    21         Btn.CommandArgument = "MyBtn";      
    22      
    23         Btn.Command += new CommandEventHandler(this.MyBtn_Command);      
    24      
    25         this.Txt = new TextBox();      
    26      
    27         this.Txt.ID = "MyTxt";      
    28      
    29         this.FindControl("form1").Controls.Add(Btn);      
    30      
    31         this.FindControl("form1").Controls.Add(Txt);      
    32      
    33 //这里还可以写成:Page.Form.Controls.Add(Txt);      
    34      
    35     }      
    36      
    37     public void MyBtn_Command(object sender, CommandEventArgs e)      
    38      
    39     {      
    40      
    41         if (e.CommandArgument.ToString() == "MyBtn")      
    42      
    43             Response.Write(Txt.Text);      
    44     } 

    以上就是动态创建和使用空间的示例,希望对你有所帮助。

  • 相关阅读:
    Silverlight 4中把DataGrid数据导出Excel
    C#正则的委托和lambda表达式用法
    C#简单的写日志方法
    GAE上传失败
    asp.net后台进程做定时任务
    ASP.NET页面生命周期描述
    巴士电台新版发布
    jQuery 1.51.7一些值得注意的更新
    wxPython应用心得
    Ajax保留浏览器历史的两种解决方案(Hash&Pjax)[转]
  • 原文地址:https://www.cnblogs.com/hfzsjz/p/1750037.html
Copyright © 2011-2022 走看看