ASP.NET动态创建控件之绝境求生第二页

本文介绍了一种在ASP.NET中动态创建控件的方法,并通过具体示例展示了如何根据需要生成指定数量的TextBox控件。文章重点讲解了通过代码动态调整页面元素的过程。

ASP.NET动态创建控件之绝境求生

日期:2007年9月8日 作者: 查看:[大字体 中字体 小字体]


  • 添加到QQ书签收藏 添加到雅虎收藏 添加到百度收藏 添加到Google书签 添加到Yahoo书签 添加到新浪ViVi 添加到搜狐网摘 添加到365Key网摘 添加到天极网摘 添加到diglog 添加到和讯网摘 添加到POCO网摘 添加到YouNote网摘 添加到博拉网 添加到天下图摘 Del.icio.us digg reddit spurl BlinkList blogmarks

    border="0" marginwidth="0" marginheight="0" src="http://www.hackhome.com/gg/web/ff_468.html" frameborder="no" width="468" scrolling="no" height="0">

  • <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script> name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-0692289505803928&dt=1206920378562&lmt=1199929998&format=300x250_as&output=html&correlator=1206920378562&channel=6926205886&url=http%3A%2F%2Fwww.hackhome.com%2FInfoView%2FArticle_152410_2.html&color_bg=FFFFFF&color_text=000000&color_link=000060&color_url=008000&color_border=FFFFFF&ad_type=text_image&ref=http%3A%2F%2Fwww.hackhome.com%2FInfoView%2FArticle_152410.html&frm=0&cc=100&ga_vid=1409738354.1206920379&ga_sid=1206920379&ga_hid=579533993&flash=9.0.47.0&u_h=768&u_w=1024&u_ah=738&u_aw=1024&u_cd=32&u_tz=480&u_his=1&u_java=true" frameborder="0" width="300" scrolling="no" height="250" allowtransparency="allowtransparency">    </form>
    </body>
    </html>

     

    using System;
    using System.Data;
    using System.Configuration;
    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 _Default : System.Web.UI.Page
    {
        private int _count = 0;

        protected override void OnInit(EventArgs e)

        {
            base.OnInit(e);

            // 取得以前已创建控件的个数
            if (!String.IsNullOrEmpty(this.Request["hfCount"]))
            {
                _count = Convert.ToInt32(this.Request["hfCount"]);
            }

            // 假如按下“Add”按钮,那么count加一
            string target = this.Request["btnAdd"];
            if (target == "Add")
            {
                _count++;
            }

            // 动态创建控件
            for (int i = 0; i < _count; i++)
            {   // 这里以TextBox为例,实际上需要创建的是WebPartZone
                TextBox newTextbox = new TextBox();
                newTextbox.ID = "TXT" + i.ToString();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值