如何在手风琴中隐藏或淡出 ValidatorCalloutExtender
我在手风琴的 3 个不同的手风琴窗格中使用 ValidatorCalloutExtender 来实现不同的 asp 控件。当我收到错误并单击另一个手风琴窗格标题时,错误消息将显示在浏览器的左上角。如何隐藏或淡出此错误消息?
I am using ValidatorCalloutExtender for different asp controls in 3 different accordion-panes of the accordion. When I get error and I click the other accordion-pane header the error message is showing up on left top corner of the browser. How to hide or fade out this error message?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想你现在已经明白了这一点(4 个月?)。但我认为这是一个有趣的挑战,而且我之前也曾与验证者打过交道。
解决方案是挂钩 Accordion 控件的 SelectedIndexChanged 事件并禁用隐藏窗格的所有验证器。
首先,我们必须向手风琴控件添加一个钩子。这使用了 jQuery(我不知道还有什么其他方法可以实现这一点)。该变量包含手风琴函数的客户端 ID。
当然,这都是客户端(javascript)。
之后,我们需要创建 onAccordionPaneChanged 方法来循环遍历折叠窗格中的所有 DIV,并禁用与隐藏 DIV 关联的所有验证器(并启用新打开的 DIV 的所有验证器):
请注意,在上面,它提到每个窗格有两个 DIV。所发生的情况是,手风琴控件为每个窗格创建两个 DIV:一个用于页眉,另一个用于页脚。如果循环遍历所有子级,则每隔一个 DIV 都是包含内容的 DIV。因此,为了仅禁用内容部分中的所有验证器,上面我检查了 (i%2 == 1),它表示这是一个“奇数”div,即内容 div。
最后,EnableDisableValidators 函数获取给定的 DIV 并检查所有页面的验证器以查看它们是否是该 DIV 内的控件。如果它们位于此 DIV 内,它将根据传入的值(取决于此 DIV 是否是选定的 DIV)来启用或禁用验证器。
不幸的是,由 Accordion 控件生成的 DIV 没有 ID,因此您必须专门搜索 div 中的所有控件。
另一个缺点是我们必须找到 DIV 中的所有子控件,为此我们必须查找该 DIV 中的所有子控件。必须使用递归。因此,这里有一个“简单”函数(如上所述):
这种方法存在一些问题。首先,当您提交表单时,只有当前窗格中可见的验证器才会发布错误。所有隐藏的验证器都不会显示。要解决此问题,您可以添加提交按钮的“onclick”函数,该函数将循环遍历所有 Page_Validators 并在提交之前启用它们。您可能(此时)还必须检查验证器。但这是一个完全不同的问题。 ;)
另一个问题是,当您单击扩展器所附加的控件时,扩展器似乎会自行显示。当启用验证器功能以显示哪些字段是必需的时,您可以使用相同的功能来调用验证器功能。 (只是一个可能的解决方案。)但同样,这是一个完全独立的问题!
希望这有帮助。
I presume you've figured this out by now (4 months?). But I saw this as a fun challenge and I've dealt with validators before.
The solution is to hook into the SelectedIndexChanged event for the accordion control and disable all the validators for the hidden panes.
First, we have to add a hook to the accordion control. This uses jQuery (I don't know of any other way to accomplish this). The variable contains the Client ID of the accordian function.
This is all client side, of course (javascript).
After that, we need to create the onAccordionPaneChanged method to loop through all the DIVs in the accordian pane and disable all the validators associated with the hidden DIVs (and enable all the validators for the newly opened DIV):
Note that in the above, it mentions the two DIVs per pane. What happens is that the accordian control creates two DIVs per pane: one for the header and then one for the footer. If you loop through all the children, every other DIV is the one that contains the Content. So, to disable all the validators in only the content sections, above I checked (i%2 == 1) which says this is an "odd" div which are the content divs.
Finally, the EnableDisableValidators function takes the given DIV and checks all the Page's validators to see if they are controls within this DIV. If they are inside this DIV, it will either enable or disable the validator, based on the passed in value (which is determined by whether this DIV is the one that was selected).
Unfortunately, the DIVs that are generated by the Accordion control don't have an ID, so you have to search through all the controls within the div specifically
Another downfall is that we have to find all the children within the DIV and to do that we have to use recursion. So, here's a "simple" function for that (called above):
There's a few problems with this approach. First, when you submit the form, only the validators that are visible in the current pane will post an error. All the hidden validators won't be shown. To resolve this, you could add a function "onclick" of the submit button that would loop through all the Page_Validators and enable them all before you submitted. You may (at that point) also have to check the validators. But that's an entirely different question. ;)
Another problem is that the extenders seem to show themselves when you click on the control that they are attached to. You could use this same functionality to call the validators functionality when they are enabled to show which fields are required. (Just a possible solution.) But again, that's a whole separate question!
Hopefully that helps.