Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 动态控件未显示在页面上_C#_Asp.net_Code Behind_Web Controls - Fatal编程技术网

C# 动态控件未显示在页面上

C# 动态控件未显示在页面上,c#,asp.net,code-behind,web-controls,C#,Asp.net,Code Behind,Web Controls,这是相对直截了当的,但我显然错过了一步,在解决我的问题上找不到支持 我只是想在我的页面上添加一个动态创建的控件,但这并没有发生。以下是我所做工作的精简版本: Button button = new Button(); button.Click += new EventHandler(btnTakeAction_Click); button.Text = "Take Action"; button.ID = "btnTakeAction"; fullPayOnlyCoupon = string.F

这是相对直截了当的,但我显然错过了一步,在解决我的问题上找不到支持

我只是想在我的页面上添加一个动态创建的控件,但这并没有发生。以下是我所做工作的精简版本:

Button button = new Button();
button.Click += new EventHandler(btnTakeAction_Click);
button.Text = "Take Action";
button.ID = "btnTakeAction";
fullPayOnlyCoupon = string.Format(
    "<div>Some random text. I want my control to show up here: {0}</div>", button);
但是
控件onaspxpage
不会呈现我动态创建的按钮。

尝试使用


每次在
Page\u Load
事件中都必须创建动态控件。 下面是一个解释:
(1)什么类型的
控件onaspxpage
?(2) 你在哪里(
Page\u Load
maybe)运行这些代码?你是否尝试将“ControlOnAspxPage”作为一个面板。同时还要确保您没有自动重定向/刷新页面,这会导致控件很快消失,因为它是一个动态控件。其余代码在“我的系统”上运行良好!您好,您不需要在占位符中添加动态控件,您可以将动态控件添加到所需的每个现有控件;-)
Button button = new Button();
button.Click += new EventHandler(btnTakeAction_Click);
button.Text = "Take Action";
button.ID = "btnTakeAction";
ControlOnAspxPage.Controls.Add(button);
<asp:PlaceHolder
  EnableTheming="True|False"
  EnableViewState="True|False"
  ID="string"
  OnDataBinding="DataBinding event handler"
  OnDisposed="Disposed event handler"
  OnInit="Init event handler"
  OnLoad="Load event handler"
  OnPreRender="PreRender event handler"
  OnUnload="Unload event handler"
  runat="server"
  SkinID="string"
  Visible="True|False"
/>
myButton = new HtmlButton();
myButton.InnerText = "Button 2";
PlaceHolder1.Controls.Add(myButton);