本文介绍了设置ASP:内容的ContentPlaceHolder编程方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是设置的&LT内容的最简单的方法; ASP:&的ContentPlaceHolder GT;
编程?我想生病必须做一个 Master.FindControl
打电话?
What is the easiest way to set the contents of an <asp:ContentPlaceHolder>
programatically? I imagine ill have to do a Master.FindControl
call?
推荐答案
如果您的网页从MasterPage的继承,那么你应该有一个asp:内容控制在页面上的一些标识,像这样:
If your page inherits from a MasterPage, then you should have an asp:Content control on your page with some id, like so:
<asp:Content runat="server" ID="myContent" ContentPlaceHolderID="masterContent">
</asp:Content>
您应该能够在codebehind引用这和任何你想要添加到它。
You should be able to reference this in your codebehind and add whatever you want to it.
public void Page_Load( object sender, EventArgs e )
{
HtmlContainerControl div = new HtmlGenericControl( "DIV" );
div.innerHTML = "....whatever...";
myContent.Controls.Clear();
myContent.Controls.Add(div);
}
这篇关于设置ASP:内容的ContentPlaceHolder编程方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!