在 ASP.NET 中创建可折叠区域
目前我已经构建了一个崩溃控件,其行为类似于标签(关联控件ID)来控制控件的折叠状态。
我想构建以下控件:
collapsableArea http://img692.imageshack.us/ img692/3307/stackoverflowcollapseab.jpg
我想到了类似的东西:
将我已经构建的 collapsableControl 和其他一些控件(例如面板)放在一起以获得 collapsableArea。
第一次尝试:
我尝试扩展一个面板并执行了以下操作:
this.Parent.Controls.Add(collapsableControl);
但这给了我:“不正确的生命周期步骤”,“无法修改”,“nullReference”,...异常,
所以我再次尝试(我相信更好的选择,因为没有 tagKey):
我扩展了一个占位符并执行了以下操作:
this.Controls.Add(collapsableControl);
this.Controls.Add(collapsablePanel);
这导致了其他问题,例如:我只想设置面板的文本,面板的样式,...
有线!
对于这种情况你有什么解决方案吗?
编辑:
我想出了另一个解决方案:
另一个解决方案http://img109.imageshack.us/img109/3307/stackoverflowcollapseab.jpg< /a>
“CollapsableArea” 的类型为“Control”,包含 2 个额外的私有属性:
- “CollapsableControl”
- “Panel”
我认为将 CollapsableArea.Controls 的 getter 重定向到 CollapsableArea.Panel.Controls 就足够了。在 CollapsableArea.CreateChildControls() 中,我实例化并将 CollapsableControl 和 Panel 添加到 base.Controls 中,并在 CollapsableArea.RenderChildren() 中渲染
我现在的两个问题: CollapsableControl 将获取 clientID(无需设置 ID)- 面板不会 如果面板包含 <% %> 标签,渲染 CollapsableControl 将失败(或失效),
有什么建议吗?
编辑: 我修复了丢失 ID 的行为 - 只需将 CollapsableControl.AssociatedControlID 设置为 Panel.ClientID...但是 - 当放置 <% %> 时在面板中,它不会被渲染?!!
currently i've built a collapseControl which behaves similar to a label (associatedControlID) to control the collapse-state of a control.
following control i'd like to build:
collapsableArea http://img692.imageshack.us/img692/3307/stackoverflowcollapseab.jpg
i thought of something like:
put my already build collapsableControl and some other control (eg. panel) together to get a collapsableArea.
first try:
i tried to extend a panel and did the following:
this.Parent.Controls.Add(collapsableControl);
but this gave me: "not correct life cycle step", "can't modify", "nullReference", ... exceptions
so i gave it another try (which i believe the better choice, due to getting no tagKey):
i extended a placeholder and did the following:
this.Controls.Add(collapsableControl);
this.Controls.Add(collapsablePanel);
this caused other problems, like: i only want to set the text of the panel, the style of the panel, ...
wired!
do you have any solutions for this scenario?
edit:
i came up with another solution:
another solution http://img109.imageshack.us/img109/3307/stackoverflowcollapseab.jpg
"CollapsableArea" is of type "Control", containing 2 extra private properties:
- "CollapsableControl"
- "Panel"
i thought it would be enough, to redirect the getter of the CollapsableArea.Controls to CollapsableArea.Panel.Controls. in CollapsableArea.CreateChildControls() i instanciate and add the CollapsableControl and Panel to base.Controls and in CollapsableArea.RenderChildren() render those 2
my problems now:
the CollapsableControl will get a clientID (without setting an ID) - the panel won't
render CollapsableControl will fail (or passed out), if panel contains <% %>-tags
any suggestions?
edit:
i fixed the behaviour of the missing ID - just set CollapsableControl.AssociatedControlID to Panel.ClientID... but - when putting <% %> in the panel, it won't get rendered??!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想要一个简单的面板,而不是重新发明轮子,您可以使用可折叠面板控件:
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/CollapsiblePanel/CollapsiblePanel.aspx
可能是获得您想要的功能的最简单方法?
If you are after a simple panel, rather then re-inventing the wheel you could use the Collapsible Panel Control:
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/CollapsiblePanel/CollapsiblePanel.aspx
Might be the easiest way to get the functionality you are after?
哦,怎么回事 - 我已经解决了这个问题:
oh, how comes - i've solved this problem:
您的控件应该获取模板控件属性来定义可折叠内容。正如您所说,AssociatedControlID 属性获取 Label 控件 id。
您必须将 jquery 注册到页面的启动脚本。
Your control should get a Template control property to define collapsable content. And as you said a AssociatedControlID property which gets the Label control id.
You have to register a jquery to the startup scripts of the page.