在 ListView 中使用 UpdatePanel

发布于 2024-08-29 06:11:55 字数 1043 浏览 2 评论 0原文

我想知道以前是否有人遇到过类似的事情。一些快速的伪代码可以开始:

<UpdatePanel>
    <ContentTemplate>
        <ListView>
            <LayoutTemplate>
                <UpdatePanel>
                    <ContentTemplate>
                        <ItemPlaceholder />
                    </ContentTemplate>
                 </UpdatePanel>
            </LayoutTemplate>
            <ItemTemplate>
                 Some stuff goes here
            </ItemTemplate>
        </ListView>
    </ContentTemplate>
</UpdatePanel>

从上面的主要内容中可以看出,我有一个包含列表视图的更新面板;然后每个列表视图项目都包含在其自己的更新面板中。

我想做的是,当 ListView 更新面板之一触发回发时,我还想更新其他 ListView 项目更新面板之一。

实际的实施方式是进行一项快速调查,其中包含 3 个问题。如果用户对问题 1 回答“是”,我们只会询问问题 3。当页面加载时;它隐藏了 Q3,因为它没有看到 Q1 的“是”。当用户对 Q1 单击“是”时,我想刷新 Q3 更新面板以便现在显示。

我现在通过在回发时刷新外部 UpdatePanel 来使其工作,但这似乎效率低下,因为我不需要重新评估每个项目;只是那些会受到我上面详述的先决条件影响的人。

我一直在努力设置触发器,但我一直一无所获,主要是因为我无法找到一种方法来根据 Q1 触发的回发为 Q3 的更新面板设置触发器。

有什么建议吗?我是不是找错了树?

I'm wondering if anybody has run across something similar to this before. Some quick pseudo-code to get started:

<UpdatePanel>
    <ContentTemplate>
        <ListView>
            <LayoutTemplate>
                <UpdatePanel>
                    <ContentTemplate>
                        <ItemPlaceholder />
                    </ContentTemplate>
                 </UpdatePanel>
            </LayoutTemplate>
            <ItemTemplate>
                 Some stuff goes here
            </ItemTemplate>
        </ListView>
    </ContentTemplate>
</UpdatePanel>

The main thing to take away from the above is that I have an update panel which contains a listview; and then each of the listview items is contained in its own update panel.

What I'm trying to do is when one of the ListView update panels triggers a postback, I'd want to also update one of the other ListView item update panels.

A practical implementation would be a quick survey, that has 3 questions. We'd only ask Question #3 if the user answered "Yes" to Question #1. When the page loads; it hides Q3 because it doesn't see "Yes" for Q1. When the user clicks "Yes" to Q1, I want to refresh the Q3 update panel so it now displays.

I've got it working now by refreshing the outer UpdatePanel on postback, but this seems inefficient because I don't need to re-evaluate every item; just the ones that would be affected by the prerequisite i detailed out above.

I've been grappling with setting up triggers, but i keep coming up empty mainly because I can't figure out a way to set up a trigger for the updatepanel for Q3 based off of the postback triggered by Q1.

Any suggestions out there? Am I barking up the wrong tree?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如痴如狂 2024-09-05 06:11:55

老实说,这可能会更好地用纯 JavaScript 完成,最初隐藏元素并在回答问题时显示它们。不过你可能不热衷于此。我刚刚发现 UpdatePanel 非常适合简单地添加 ajax 效果,但是一旦您开始尝试做困难的事情,它就会变得过于复杂和笨重。另外,更新面板每次都会向服务器发送回邮件,如果您只是在 DOM 中打开和关闭内容,那么最好只使用 javascript。

抱歉,如果这不是您想要的答案,我只是想根据我的经验让您知道(我花了太多时间摆弄更新面板,而我本可以用 Javascript 完成事情)

To be honest, this would probably be better done in pure javascript, hide the elements initially and show them when the question is answered. You might not be keen on that though. I've just found that the UpdatePanel is great for simple adding ajax effects, but once you start trying to do hard stuff, it gets too complex and clunky. Also, the update panel does a post back to the server each time, if you are simply turning stuff on and off in the DOM it may be better to just do javascript.

Sorry if this isn't the answer you were after, just thought I'd let you know based on my experiences (I've spent too much time fiddling with update panels when I could have just done things in Javascript)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文