Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.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/37.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# 如何在asp.net中将文本动态加载到用户控件标签中?_C#_Asp.net_User Controls - Fatal编程技术网

C# 如何在asp.net中将文本动态加载到用户控件标签中?

C# 如何在asp.net中将文本动态加载到用户控件标签中?,c#,asp.net,user-controls,C#,Asp.net,User Controls,我想加载2个用户控件名,但具有不同的文本属性。 “我的用户控件”包含一个标签,该标签具有为ascx.cs中的文本定义的函数 我在运行时使用面板加载控件。在这里,我希望两个用户控件标签都有不同的文本 我的.ascx文件 <asp:Label ID="uclbl" runat="server" /> 我的.aspx文件 <asp:Panel ID="panelMain" runat="server" > </asp:Panel> 由于进行了错误的强

我想加载2个用户控件名,但具有不同的文本属性。 “我的用户控件”包含一个标签,该标签具有为ascx.cs中的文本定义的函数

我在运行时使用面板加载控件。在这里,我希望两个用户控件标签都有不同的文本

我的.ascx文件

 <asp:Label ID="uclbl" runat="server" />
我的.aspx文件

  <asp:Panel ID="panelMain" runat="server" >
   </asp:Panel>

由于进行了错误的强制转换,因此应强制转换为用户控件类型:

User1 _dummyUserControl = (User1)Page.LoadControl("~/UserControl/User1.ascx");
 _dummyUserControl.MyProperty = "SDfsdf"  ; //here you can find all your custom properties
panelMain.Controls.Add(_dummyUserControl);
您必须键入cast:

User1 _dummyUserControl = (User1)Page.LoadControl("~/UserControl/User1.ascx");

你打了我4秒钟D:D:D我想他不会相信这么快的回答,我不知道我们必须打字…虽然很容易解决…你们回答的速度很快。注意:我需要添加using.ProjectName.UserControl
User1 _dummyUserControl = (User1)Page.LoadControl("~/UserControl/User1.ascx");
 _dummyUserControl.MyProperty = "SDfsdf"  ; //here you can find all your custom properties
panelMain.Controls.Add(_dummyUserControl);
User1 _dummyUserControl = (User1)Page.LoadControl("~/UserControl/User1.ascx");