zoukankan      html  css  js  c++  java
  • asp.net动态添加控件

    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 Default3 : System.Web.UI.Page
    {
        
    public bool IsDynamicLoadControl
        
    {
            
    get
            
    {
                
    object dynamic = ViewState["IsDynamicLoadControl"];
                
    return dynamic == null ? false : true;
            }

            
    set
            
    {
                ViewState[
    "IsDynamicLoadControl"= value;
            }

        }

        
    protected override void LoadViewState(object savedState)
        
    {
            
    base.LoadViewState(savedState);
            
    if (IsDynamicLoadControl)
            
    {
                LoadTextBox();
            }

        }


        
    protected void Page_Load(object sender, EventArgs e)
        
    {
            
    if (!IsPostBack)
            
    {
                LoadTextBox();
            }

        }

        
    private void LoadTextBox()
        
    {
            
    for (int i = 0; i < 10; i++)
            
    {
                TextBox input 
    = new TextBox();
                input.ID 
    = "input" + i.ToString();
                
    this.form1.Controls.Add(input);
            }

            IsDynamicLoadControl 
    = true;
        }

        
    protected void Button1_Click(object sender, EventArgs e)
        
    {
            TextBox tb 
    = this.FindControl("input0"as TextBox;
            Page.ClientScript.RegisterStartupScript( 
    this.GetType(),""string.Format("<script>alert('{0}')</script>", tb.Text));
        }

    }

     
  • 相关阅读:
    总结jQuery选择器
    Responsive布局技巧
    学习资料
    大公司开源项目【转载】
    针对css3特性浏览器兼容 封装less
    手把手教你nginx/linux下如何增加网站
    又一枚神器:nginx
    http://www.howtocn.org/nginx
    nginx修改内核参数
    Nginx
  • 原文地址:https://www.cnblogs.com/bobofsj11/p/1597807.html
Copyright © 2011-2022 走看看