English 中文(简体)
如何积极增加对伙伴关系的控制。 互联网的形式?
原标题:How to add controls dynamically to ASP.NET form?

我不知道如何用C# .net积极增加控制。 谁能帮助我? 我用vb.net知道这一点,但我需要了解C#中的辛奈。

问题回答

在形式上,以下法典可以动态地增加纽州:

Button button1 = new Button();
button1.Text = "dynamic button";
button1.Left = 10; button1.Top = 10;  //the button s location
this.Controls.Add(button1);

In Aspx

<%@ Reference Control = "WebUserControl1.ascx" %>

美国可以在Cs档案中使用以下文字,以动态的方式对待控制。

if (case)
else
{
WebUserControl1 uc = 
      (WebUserControl1) Page.LoadControl("WebUserControl1.ascx"); 
    PlaceHolder1.Controls.Add(uc); 


}

或审判

 Content.Controls.Add(Page.LoadControl("UserControls/InventoryNav.ascx"));

Can also have a look at:

http://aspalliance.com/565

http://samuelmueller.com/2008/12/dynamicloader-plugin-dynamically-loading-asp-net-user-controls-with-jquery”rel=“noreferer”>http://samuelmueller.com/2008/12/dynamicloader-plugin-dynamically-loading-asp-net-user-controls-with-jquery

http://forums.asp.net/p/1222567/2826338.aspx

下面是向伙伴关系提供动态控制守则。 NET表。

  1. Initialize a label
  2. Assign text to it.
  3. Initialize a panel
  4. Add the label object to the panel.
     Label lbl1 = new Label();
     lbl1.Text = "Your message here";
     Panel panel1= new Panel();
     panel1.Controls.Add(lbl1);

请参看以下样本:

更不用说姓名是左边。

Button btnSave = New Button();
frmMain.Controls.Add(btnSave)

下面是关于一些事件的守则,如上页或上载或甚至一些用户行动,如上表。

protected void add_button(Button btn)
{
   try
   {
        panel1.Controls.Add(btn); // Add the control to the container on a page
   }
   catch (Exception ee)
   {
         lblError.Text = ee.Message.ToString();
   }
}

在小组中增加控制,不论是在标识或方案上添加小组,都是不可接受的。

See the following link for C# syntax





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签