如果直立的 UserControl 不可见,则不要填充 DropDownList

发布于 2024-08-01 15:49:39 字数 481 浏览 2 评论 0原文

我的 Add.aspx 页面包含许多 UserControls:AddRequest.ascx、AddOperation.ascx、AddObject.ascx 等。取决于 Request["type"] 一个控件变得可见。

每个UserControl 包含许多DropDownList,这些DropDownList 是通过数据库中的SqlDataSource 填充的。 例如,类型、状态、货币等。

似乎适当的 SqlDataSource 会查询数据库,即使它的 UserControl 所有者不可见。 因此,拥有 n 个控件,实际上只需要 1 查询,而不需要 n-1

我怎样才能改变这种行为?

I have page Add.aspx containing a number of UserControls: AddRequest.ascx, AddOperation.ascx, AddObject.ascx, etc. Depending on Request["type"] one control becomes visible.

Each UserControl contains a number of DropDownLists that are being filled via SqlDataSource from DB. For example, types, statuses, currencies, etc.

It seems that appropriate SqlDataSources queries DB even if it's UserControl-owner isn't visible. So having n controls, only 1 query is really needed and n-1 are not.

How can I change this behavior?

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

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

发布评论

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

评论(2

嗳卜坏 2024-08-08 15:49:39

尝试使用户控件的加载本质上是命令式的(如 @Dante 所示)而不是声明式的(例如,通过在 ASPX 中注册)。 这样,只有显式加载的控件才应调用其各自的数据源控件)。

Try making the loading of the usercontrols imperative in nature (as demonstrated by @Dante) instead of declarative (by registering it in the ASPX, for instance). That way, only that control which is explicitly loaded should invoke it's respective Datasource controls).

打小就很酷 2024-08-08 15:49:39

如果我理解正确,您应该只加载要显示的用户控件。
类似于:

Control myControl = LoadControl("SomeControl.ascx");

然后您可以将控件添加到占位符。
这样您就可以避免将不必要的控件加载到页面,并且它们到数据库的往返也不会执行。

If I understood correctly, you should only load the user control you are going to display.
Something like:

Control myControl = LoadControl("SomeControl.ascx");

You can then add the control to a placeholder.
This way you avoid loading unnecessary controls to your page and their round trips to the database are also not executed.

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