how to hosting webform visual designer? RRS feed

  • 问题

  • if it is impossible then how to implent programmatically add server control to a page object at design time, for example:

    this.Controls.Add(New GridView(){Title="title",Width="800"});

    • 已编辑 losts 2012年1月31日 7:27
    • 已移动 Vicky SongMicrosoft employee 2012年2月2日 6:36 ASP.NET issue (发件人:Visual Studio 相关讨论(Visual Studio 2010以前版本))
    2012年1月31日 7:26


  • Hi Partner,

    I am moving your case to the ASP.NET forum so that you can get better support there.


    Vicky Song [MSFT]
    MSDN Community Support | Feedback to us
    2012年2月2日 6:36
  • No,this code can be used for dynamically adding controls onto the server page manually at code-behind。If you want to Add Controls at design time:

    1)Directly drag and drop the control onto the page。

    2)Maybe you should create another class that inherits from Composite control,and then override the CreateChildrenControl method to add dynamically controls inside,Don't forget to set ChildControlsCreated=True;in the end,override your RecreateChildControls method。Sample looks like this below(if you compile the whole sample package,and drag and drop the control onto the page,you can see the dynamically-added controls like Label,literatures……,ect defined in the CreateChildControls)

    namespace WebCSharp
        public class ServerControl1 : CompositeControl
            int pageSize;     //每页显示行数   
            int nMax;         //总记录数   
            int pageCount;    //总页数=总记录数/每页显示行数   
            int nCurrent;      //当前记录行

            Label mTab;
            Label CountLab;
            Button Fpage;
            Button Ppage;
            Label CurrLab;
            Button Npage;
            Button Lpage;
            Panel pc;

            public string sql
                    String s = (String)ViewState["sql"];
                    return s;

                    ViewState["sql"= value;

            public int pageCurrent
                    int s = ViewState["pageCurrent"]==null?1:(int)ViewState["pageCurrent"];
                    return s;

                    ViewState["pageCurrent"= value;

            protected override void OnInit(EventArgs e)
            protected override void CreateChildControls()

                mTab = new Label();

                CountLab = new Label();
                Fpage = new Button();
                Ppage = new Button();
                CurrLab = new Label();
                Npage = new Button();
                Lpage = new Button();
                pc = new Panel();

                mTab.ID = this.ID + "mTab";
                CountLab.ID = this.ID + "CountLab";
                Fpage.ID = this.ID + "Fpage";
                Ppage.ID = this.ID + "Ppage";
                CurrLab.ID = this.ID + "CurrLab";
                Npage.ID = this.ID + "Npage";
                Lpage.ID = this.ID + "Lpage";
                pc.ID = this.ID + "pc";

                Fpage.Text = "首页";
                Ppage.Text = "上页";
                Npage.Text = "下页";
                Lpage.Text = "末页";

                Fpage.Click += new EventHandler(Fpage_Click);



                this.ChildControlsCreated = true;


            protected override void RecreateChildControls()
                if (this.ChildControlsCreated == false)

            protected override void RenderContents(HtmlTextWriter output)
                pageSize = 15;     //每页显示行数   
                nMax = 0;         //总记录数   
                pageCount = 0;    //总页数=总记录数/每页显示行数   
                pageCurrent = 1;   //当前页号   
                nCurrent = 0;      //当前记录行

            void Fpage_Click(object senderEventArgs e)
                Fpage.Text = pageCurrent.ToString();
                Npage.Text = pageCurrent.ToString();

    2012年2月2日 7:02
  • Thanks For Your Replay!

    but I need programmatically add server control to a page at design time using the visual designer in a visual studio add-in or by hosting the designer.

    why my posts moved  here.

    2012年2月2日 8:31