ASP.NET 中 MultiView 的替代方案

发布于 2024-08-18 17:01:05 字数 152 浏览 10 评论 0原文

我正在构建的网站包含大量视图,这些视图将显示在同一位置,但根据用户导航菜单的方式隐藏或显示。

当你有一个包含 10 个不同视图的 MultiView 时,视觉工作室设计视图会变得非常混乱。我已经将每个视图的内容分离到多个用户控件中。但是有 MultiView 的替代方案吗?

The website I'm building contains a large number of views which will be displayed on the same place but hidden or shown according to how the user navigates the menu.

It gets quite messy in visual studios design view when you have a MultiView with 10 different views in it. I've already separated the content of each view in several user controls. But is there an alternative to MultiView?

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

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

发布评论

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

评论(3

伤痕我心 2024-08-25 17:01:05

我通常只使用面板或占位符并手动切换可见性。但我也不使用 VS 设计器......

I generally just use a Panel or Placeholder and toggle visibilities manually. But then I don't use the VS designer either...

罪歌 2024-08-25 17:01:05

假设您在这里使用 ASP.NET Web 表单...

这是投资一些功能强大的 Web 控件(例如 Telerik ASP.NET 控件套件)的另一个原因。

您可以将其 RadTabStrip 控件与 RadMultiPage 控件一起使用。

示例如下: http://demos. telerik.com/aspnet-ajax/tabstrip/examples/multipage/loading-external-content/defaultcs.aspx

您可以为每个 RadPageView 指定一个 ContentUrl,它允许您将每个视图分成单独的 aspx 文件。

这通过将每个视图分离到各自的页面中来简化您的解决方案,并提高性能,因为仅在最初查看时才请求 RadPageView 内容。

Assuming you're using ASP.NET webforms here...

This is another reason to invest in some powerful web controls like the Telerik ASP.NET control suite.

You could use their RadTabStrip control along with the RadMultiPage control.

Example here: http://demos.telerik.com/aspnet-ajax/tabstrip/examples/multipage/loading-external-content/defaultcs.aspx

You can specify a ContentUrl for each RadPageView which allows you to separate each view into separate aspx files.

This simplifies your solution by separating each view into their own page and increases performance as RadPageView content is requested only when viewed initially.

盛夏尉蓝 2024-08-25 17:01:05

我执行此操作的方法是在页面上放置一个占位符,并根据需要动态向其添加控件。

从你所说的来看,用户似乎导航了一个菜单,这决定了在 MultiView 控件中显示哪个视图...

我想要这样的

ASPX 文件:

<asp:PlaceHolder id=phContentContainer" runat="server"></asp:PlaceHolder>

代码隐藏

switch (MenuSelection)
{
     case "LOGIN" //Display the login control
     {
        ucLoginUserControlType loginControl = (ucLoginUserControlType)LoadControl("~/UserControls/ucLoginUserControlType.ascx");

        phContentContainer.Controls.Add(loginControl);
     }
}

显然,你会想要稍微处理代码隐藏比上面的 10 个视图更高效、更干净……但你明白了。

这使您的 aspx 页面保持简单,并使将来添加的控件更容易实现。

希望这会有所帮助,我是凭记忆输入代码的,所以有些语法可能不正确 - 如果你不能让它运行,请给我喊一声,我会找出一些我完成此操作时的示例。

祝你好运!

The way that I would do this would be to have a placeholder on the page and dynamically add controls to it as needed.

From what you have said it looks like the user navigates a menu and this decides which view to display in the MultiView control...

I would so something like this

ASPX file:

<asp:PlaceHolder id=phContentContainer" runat="server"></asp:PlaceHolder>

Code Behind

switch (MenuSelection)
{
     case "LOGIN" //Display the login control
     {
        ucLoginUserControlType loginControl = (ucLoginUserControlType)LoadControl("~/UserControls/ucLoginUserControlType.ascx");

        phContentContainer.Controls.Add(loginControl);
     }
}

Obviously you will want to work the codebehind to be a bit more efficient and cleaner than the above would be with 10 views... but you get the idea.

This keeps your aspx page simple and makes future control additions easier to implement.

Hope this helps, I have typed the code from memory, so some syntax may not be right - if you cant get it going give me a shout and Ill dig out some examples of when I have done this.

Good luck!

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