asp:multiview control - 我们可以在一个选项卡上而不是不同的选项卡上显示所有视图吗

发布于 2024-12-14 15:54:29 字数 166 浏览 4 评论 0原文

我在代码中使用了多视图控件,在页面上显示 5 个视图。目前,我正在尝试使用 CSS 实现“打印”功能,我想要的是将所有 5 个视图一起显示,以便于打印。

那么,是否可以一次显示多视图中的所有视图。某事比如显示所有视图或显示所有视图,

如果我可以一次显示所有视图,我可以解决我的打印功能。

I have used a Multiview control in my code where i display 5 views on my page. Currently, I am trying to implement "Print" functionality" using CSS and what I want is to display all the 5 views together so it is easy to print.

So, is it possible to display all the views in a multiview at once. something like show all views or display all views.

I can work around my print functionality if I can display all the views at once. Please help me.

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

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

发布评论

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

评论(1

感悟人生的甜 2024-12-21 15:54:29

我相信 MultiView 控件默认不支持此功能。您可以做的是实现从现有控件继承的自己的 MultiView 控件,并向其添加所需的功能:

[DefaultProperty("Text")]
[ToolboxData("<{0}:MyMultiView runat=server></{0}:MyMultiView>")]
public class MyMultiView : MultiView
{
    [Category("Behavoir")]
    [DefaultValue(false)]
    public bool RenderAllAtOnce
    {
        get
        {
            return (bool)(ViewState["RenderAllAtOnce"]?? false);
        }

        set
        {
            ViewState["RenderAllAtOnce"] = value;
        }
    }

    protected override void Render(HtmlTextWriter writer)
    {
        if (!RenderAllAtOnce)
        {
            base.Render(writer);
        }
        else
        {
            foreach (View view in this.Views)
            {
                this.SetActiveView(view);
                view.RenderControl(writer);
            }
        }
    }
}

然后您可以使用该控件而不是默认控件,并在单击某些“打印”按钮时将 RenderAllAtOnce 属性设置为 true。

此外,您可以不参与新控件的创建,而只需将所有视图渲染为字符串并将其传递给页面上的某些文字:

.print
{
     display: none;
}

@media print
{
     .noPrint
     {
          display: none;
     }

     .print
     {
          display: block !important;
     }
}

<div class="noPrint">
     <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0" >
          <asp:View ID="View1" runat="server">
               AAAA
          </asp:View>
          <asp:View ID="View2" runat="server">
               BBBB
          </asp:View>
          <asp:View ID="View3" runat="server">
               CCCC
          </asp:View>
     </asp:MultiView>
     <asp:Button ID="btnPrint" runat="server" Text="Print" OnClick="btnPrint_Click" />
</div>
<div class="print">
     <asp:Literal runat="server" ID="Literal1" Mode="PassThrough" />
</div>

protected void btnPrint_Click(object sender, EventArgs e)
{
    var sb = new StringBuilder();
    using (var writer = new StringWriter(sb))
    using (var htmlWriter = new HtmlTextWriter(writer))
    {
        foreach (View view in MultiView1.Views)
        {
            view.RenderControl(htmlWriter);
        }
    }

    Literal1.Text = sb.ToString();
    ClientScript.RegisterStartupScript(this.GetType(), "print", "window.print();", true);
}

I believe that the MultiView control doesn't support this feature by default. What you can do is to implement own MultiView control inherited from the existing one and add to it desired functionality:

[DefaultProperty("Text")]
[ToolboxData("<{0}:MyMultiView runat=server></{0}:MyMultiView>")]
public class MyMultiView : MultiView
{
    [Category("Behavoir")]
    [DefaultValue(false)]
    public bool RenderAllAtOnce
    {
        get
        {
            return (bool)(ViewState["RenderAllAtOnce"]?? false);
        }

        set
        {
            ViewState["RenderAllAtOnce"] = value;
        }
    }

    protected override void Render(HtmlTextWriter writer)
    {
        if (!RenderAllAtOnce)
        {
            base.Render(writer);
        }
        else
        {
            foreach (View view in this.Views)
            {
                this.SetActiveView(view);
                view.RenderControl(writer);
            }
        }
    }
}

Then you can use that control instead of the default one and set RenderAllAtOnce property to true on some Print button click.

Also you can don't involving in new control creation and just render all views to string and pass it to some literal on a page:

.print
{
     display: none;
}

@media print
{
     .noPrint
     {
          display: none;
     }

     .print
     {
          display: block !important;
     }
}

<div class="noPrint">
     <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0" >
          <asp:View ID="View1" runat="server">
               AAAA
          </asp:View>
          <asp:View ID="View2" runat="server">
               BBBB
          </asp:View>
          <asp:View ID="View3" runat="server">
               CCCC
          </asp:View>
     </asp:MultiView>
     <asp:Button ID="btnPrint" runat="server" Text="Print" OnClick="btnPrint_Click" />
</div>
<div class="print">
     <asp:Literal runat="server" ID="Literal1" Mode="PassThrough" />
</div>

protected void btnPrint_Click(object sender, EventArgs e)
{
    var sb = new StringBuilder();
    using (var writer = new StringWriter(sb))
    using (var htmlWriter = new HtmlTextWriter(writer))
    {
        foreach (View view in MultiView1.Views)
        {
            view.RenderControl(htmlWriter);
        }
    }

    Literal1.Text = sb.ToString();
    ClientScript.RegisterStartupScript(this.GetType(), "print", "window.print();", true);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文