开发者

How to place an item in an existing DIV in the master page?

I have a master page with three DIV blocks, say div1, div2, div3. I have a Content Web Form which is linked to this master page. From this 开发者_开发问答content form, I want to programatically, write lines in say div2. How to do call this div of the master page? I mean what to write inside the tags to embed text in this div?


If you add the runat="server" attribute to the div in your MasterPage you can reference this div using it's ID attribute either from the MasterPage or from the content page by first referencing the Master property in your page.

from the .cs file of your Content Page you could do something like

Master.MyDiv

where MyDiv is the id of the div in the MasterPage.

You could also put a PlaceHolder (NOT ContentPlaceHolder) control in your MasterPage and then reference the control from your page (Master.MyPlaceHolder) and add controls to it from your page.


If your <div> elements have a unique id attribute, and their runat attribute is set to server (so that ASP.NET can know about them), you can do:

Page.Master.FindControl("yourDivID").Controls.Add(
    new LiteralControl("Your<br />additional<br />lines."));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜