如何在代码后面使用div的id在div中放置一个控件? [英] How to place a controls inside div using id of div in code behind?

查看:205
本文介绍了如何在代码后面使用div的id在div中放置一个控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友



1st我将在代码后面创建2个div这样的



 sb.Append( < div id = left   style =  float :left; width:50%  >); 







 sb.Append( < div id = right   style =  float :right; width:50% > ); 





现在我想使用div的ID在div中放置多个控件



如果我想把控制放在右边它应该放在右侧div使用id'right'



如果我想放置控制在左边它应该放在左侧id'左'



注意:所有代码背后



如何实现..

解决方案

参考:



1)从代码后面添加文本框服务器控件?



2)如何将代码中创建的控件放在页面上?



3)在InnerHTML内向代码隐藏页面添加ASP控件


只要您使用字符串构建器创建页面内容,就无法添加动态控件...

您需要做的是向父控件的Controls属性添加控件...

这样的东西:

< pre lang =c#> HtmlGenericControl oDiv = new HtmlGenericControl( );
标签oLabel = 标签();

oDiv.Controls.Add(oLabel);

Page.Controls.Add(oDiv);


Hi Friends

1st i will create 2 divs in code behind like this

sb.Append("<div id="left" style="float:left;width:50%">");



and

sb.Append("<div id="right" style="float:right;width:50%">");



now i want to place multiple controls inside the div using the ids of div

if i want to place control on right it should be placed on right side div using id 'right'

if i want to place control on left it should be placed on left side id 'Left'

Note: All in code behind

How to achive it..

解决方案

Ref :

1 ) adding a textbox server control from code behind?

2 ) How do I place a control created in the code behind on a page?

3 ) Adding a ASP Control to page from Code Behind within InnerHTML


As long as you create your page content as using string builder you can not add dynamic controls...
What you have to do is adding controls to the parent control's Controls property...
Something like this:

HtmlGenericControl oDiv = new HtmlGenericControl("div");
Label oLabel = new Label();

oDiv.Controls.Add(oLabel);

Page.Controls.Add(oDiv);


这篇关于如何在代码后面使用div的id在div中放置一个控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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