如何从asp网页

时间:2017-11-15 16:58:03

标签: javascript c# jquery asp.net

我在cshtml中有此页面。 此页面在“formImpressao”(ASP.NET PAGE)

中执行提交

CSHTML页面

@using Web.Mvc.Helpers
@{
    string msgSucesso = "test";      
}
<div id="divSucess">
<h5 style="background-image: url('themes/base/images/48/ico_ok.gif'); text-align:center; background-repeat: no-repeat; font-family: Verdana; color: #1d7100; font-size:'72'">@msgSucesso</h5>
</div>


<div id="HiddenFormTarget" style="display:none;">
    <form id="formImpressao" method="post" target="frmPrint" action="/VisualizarRelatorios/ImprimirRelatorio.aspx"></form>
</div>
<iframe id="frmPrint" name="frmPrint" width="0" height="0" runat="server">
</iframe>


<script language="javascript" type="text/javascript">
    $("#formImpressao").submit();
</script>

ASPX页面(ImprimirRelatorio.aspx)

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ImprimirRelatorio.aspx.cs" Inherits="Views.Views.ImprimirRelatorios.ImprimirRelatorio" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<%--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">--%>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../Scripts/jquery-1.5.1.js" type="text/javascript"></script>
    <script src="../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>    
</head>
<body style="margin: 0px">

    <form id="form1" runat="server"  style=" width:100%; height:100%;" >
    <div style=" width:100%; height:100%; overflow-y:hidden; overflow-x:hidden" >
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <rsweb:ReportViewer ID="rptRelatorio" runat="server" Width="100%"
            Height="100%" ProcessingMode="Remote" >
        </rsweb:ReportViewer>
    </div>
    </form>
</body>
</html>
<script language="javascript">

    function Imprimir()
    {
        var viewer = $find("rptRelatorio");
        var isLoading = viewer.get_isLoading();
        var impresso = false;

        if (!isLoading) {
            $("input[type='image']:not(:disabled)[title*='Print']").click();
            impresso = true;
        }

        if (!impresso) {
            setTimeout(Imprimir, 1000);
        }else {
          $("#divSucess").style.backgroundColor = "red"; 
        }

    }

    $(document).ready(function () {
        setTimeout(Imprimir, 4000);
    });

</script>

Imprimir函数验证报表是否在Reporting Services中打印。

如果打印,则需要分配给div divSuccess,属性为:style.backgroundColor = "red"

问题是asp表单没有看到divSuccess,而cshtml页面没有显示asp表单。

如何调用asp页面中的js函数来播放具有“divSuccess”的页面的DOM?

还有其他方法吗?

两页不说话。

1 个答案:

答案 0 :(得分:0)

您可以发送AJAX请求以获取 ImprimirRelatorio.aspx 页面的内容。在成功处理程序中,您可以解析响应以获取 ImprimirRelatorio.aspx 页面的body标签的内部HTML,将结果设置为某个容器(不包含<iframe>)并调用Imprimir函数(详见AJAX documentation)。注意,Imprimir函数应该是成功事件处理程序的一部分,应该在调用页面中定义。