简体   繁体   English

如何在代码中包装我的用户控件?

[英]How can I wrap my user control in code behind?

In my jquery I do: 在我的jquery我做:

var userControl = $('#userControl').wrap('<li />').parent()

how can I do that on the server? 我怎么能在服务器上这样做? So far I have: 到目前为止,我有:

UserControl userControl = Page.LoadControl("~/Controls/userControl.ascx");
Content.Controls.Add(userControl);

Try using a PlaceHolder. 尝试使用PlaceHolder。 A PlaceHolder does not load a container element. PlaceHolder不加载容器元素。 Assume that the Placeholder is called plcTest: 假设占位符被称为plcTest:

 UserControl userControl = Page.LoadControl("~/Controls/userControl.ascx");
 plcTest.Controls.Add(userControl);

Frontend code would look like this: 前端代码如下所示:

<li><asp:PlaceHolder ID="plcTest" runat="server" ></asp:PlaceHolder></li>

Try this: 尝试这个:

HtmlGenericControl li = new HtmlGenericControl("li");
UserControl userControl = Page.LoadControl("~/Controls/userControl.ascx");
li.Controls.Add(userControl);
Content.Controls.Add(li);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用XAML和后面的代码序列化WPF用户控件 - How can I serialize wpf user control with xaml and code behind 我怎样才能从asp.net后面的代码中包装一个带有div的控件? - how can I wrap a control with a div from the code behind in asp.net? 使用WPF自定义控件,如何通过后面的代码为自定义控件提供名称以访问它? - Using a WPF Custom Control, How can I give my custom control a name to access it via the code behind? 如何从代码后面找到span并为其添加用户控件? - How can I find span from code behind and add user control to it? 如何从后面的代码刷新自定义WPF用户控件? - How can I refresh a custom wpf user control from code behind? 如何从 xaml 中的 ItemTemplate 访问在代码中定义的用户控件的依赖项属性? - How can I access a dependency property of a user control that was defined in code behind from a ItemTemplate in xaml? 使用 NavigationView 控件,如何从后面的代码导航? - With a NavigationView control, how can I navigate from the code behind? 如何将我的代码隐藏在 MVVM 中的复选框后面? - How can I wtite my code behind for checkbox in MVVM? 如何将jQuery函数放入我的代码后面? - How can I put a jQuery function into my code behind? 如何从后面的代码访问我的 ViewModel - How can I access my ViewModel from code behind
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM