组合框 ajaxcontrol
我有一个带有 5-6 个组合框 ajax 控制工具包的过滤器面板..
我希望此过滤器面板默认可见 false..并在客户端单击时使用 java 脚本切换它(显示/隐藏),
但是当我有过滤器时面板可见 = false runat=服务器 java 脚本未获取对象
,如果我在后面执行代码..filterpanel.attributes.add("style",display:none) filterpanel.attributes.add("style",visibilty:hidden)
组合框抛出运行时错误..
我在网上搜索说..组合框很难在面板内呈现..其默认属性最初是错误的!
i have a filter panel with 5-6 combo boxes ajax control tool kit..
i want this filter panel to be visible false by default.. and toggle it(show/hide) on client click using java script
however when i have my filter panel as visible = false runat=server java script does not get the object
and if i do code behind.. filterpanel.attributes.add("style",display:none)
filterpanel.attributes.add("style",visibilty:hidden)
the combo box throws a runtime error..
i've searched on the net which says.. combo box is difficult to render inside a panel.. whose default property is initially false!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是
因此
display: none;
将不起作用,因为元素未渲染,而visibility: hide;
将部分起作用,因为元素已渲染,因此为它们分配了空间在页面上,但隐藏,因此空间将保持空白。第三种解决方案是照常渲染容器,但使其绝对定位 在浏览器视口之外:
这样,面板及其内容将不可见,但
在客户端,显示面板的公式变为:
并再次隐藏它:
您可以在 此处测试基于 jQuery 的实现。
The problem is that the
<select>
elements have to be rendered (but not necessarily visible) in order to reliably access their dimension properties.So
display: none;
won't work because the elements are not rendered, andvisibility: hidden;
will partially work because the elements are rendered, so space is allocated for them on the page, but hidden, so that space will remain empty.A third solution is to render the container as usual, but make it absolutely positioned outside of the browser viewport:
That way, the panel and its contents won't be visible, but the size of the
<select>
elements will be properly computed.On the client side, the formula to show the panel becomes:
And to hide it again:
You can test a jQuery-based implementation here.
问题是,如果您在服务器控件上设置 Visible="false",它将不会呈现任何 HTML 元素,包括组合框。使用以下方法隐藏面板是 AJAX 友好的:
它将呈现一个 DIV 和所有下拉菜单,但将它们隐藏在视图中,从而允许您切换 div 的可见性。
The issue is that if you set Visible="false" on a server control, it won't render any of the HTML elements, including the combo boxes. Hiding the panel using the following is AJAX friendly:
Which will render a DIV and all your drop downs, but hide them from view, allowing you to toggle the div's visibility.
不要将“display:none”应用于面板,仅应用“visibility:hidden”:
这将隐藏您的面板(我想是
),但保留所需的空间(因此将允许相应 DOM 元素的维度相关属性具有正确的值)。
当然,您会看到一个空位,但您可能可以通过使用元素的样式来解决此问题(也许可以通过将面板嵌套在另一个元素内并将样式应用于该元素,而不是在面板本身上执行此操作)。
Don't apply the "display: none" to the panel, only "visibility: hidden":
This will hide your panel (the
<div>
I suppose) but reserve the required space (and therefore will allow the dimension-related properties of the corresponding DOM element to have the right values).Of course you'll see an empty spot but you could probably resolve this issue by playing with the styles of an element (maybe by nesting the panel inside another element and by applying styles to that element instead of doing that on the panel itself).