如何添加相同的div动态asp.net代码 [英] how to add same div dynamically asp.net code behind

查看:76
本文介绍了如何添加相同的div动态asp.net代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何添加相同的div动态asp.net代码...我想动态添加它..

how to add same div dynamically asp.net code behind ...I want to add it dynamically..

推荐答案

这取决于你想做什么有了它,但这可能是最简单的方法。



在您的ASP页面上,您将拥有一个您想要添加DIV的父容器,例如:



It depends on what you want to do with it, but here's probably the easiest way.

On your ASP page, you would have a parent container that you wish to add your DIV to, such as:

<div id="divContainer" runat="server">
      <!-- added DIV will go inside here -->
</div>





确保您拥有'runat =server'元素ta g添加到此元素,否则你的代码将无法看到它。



然后在你的代码后面:





Make sure you have the 'runat="server"' element tag added to this element, otherwise your code behind will not be able to see it.

And then in your code behind:

divContainer.InnerHtml = "<div style=\"color:#ff0000;\">some new content goes here</div>";





或者为了更好地控制元素一旦创建,请使用:



Or for more control over the element once created, use:

System.Web.UI.HtmlControls.HtmlGenericControl divContent = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
divContent.ID = "divContent";
divContent.Style.Add(HtmlTextWriterStyle.Color, "Red");
divContent.InnerHtml = "some new content goes here";
divContainer.Controls.Add(divContent);


这篇关于如何添加相同的div动态asp.net代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆