[英]How to add controls into a SharePoint WebPart?
我可以按照以下網站上的內容制作一個簡單的Webpart :http://www.codeguru.com/csharp/.net/net_asp/webforms/article.php/c12293/但現在我想添加諸如TextBoxes之類的控件,按鈕,TreeViews ...我該怎么做? 我編碼的地方只是一個類庫! 如何使用設計器和頁面進行編碼?
盡量不要重寫WebPart類的Render方法,而應這樣重寫CreateChildControls方法:
protected TextBox txtName;
protected Button btnSubmit;
// create child control
protected override void CreateChildControls() {
txtName = new TextBox();
this.Controls.Add(txtName);
btnSubmit = new Button();
btnSubmit.Text = "Submit Name";
this.Controls.Add(btnSubmit);
}
希望這會有所幫助:
Label lb1;
protected override void CreateChildControls()
{
base.CreateChildControls();
lb1 = new Label();
lb1.ID = "label1";
lb1.Text = "Controls in webpart";
this.Controls.Add(lb1);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.