简体   繁体   English

如何从ASP网页调用js extern函数

[英]How to call js extern function from asp net page

I have this page in cshtml . 我在cshtml有此页面。 This page execute submit in "formImpressao" (ASP.NET PAGE) 该页面在“ formImpressao”(ASP.NET PAGE)中执行提交

CSHTML 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 Page (ImprimirRelatorio.aspx) 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>

The Imprimir function on validates whether the report was printed within Reporting Services. Imprimir函数on验证报告是否在Reporting Services中打印。

If printed, it needs to assign to div divSuccess , the attribute: style.backgroundColor = "red" . 如果已打印,则需要将其分配给div divSuccess ,属性为: style.backgroundColor = "red"

The problem is that the asp form does not see the divSuccess and the cshtml page does not display the asp form. 问题是asp表单看不到divSuccess ,而cshtml页面没有显示asp表单。

How can I call a js function inside the asp page to play the DOM of the page that has the " divSuccess "? 如何在asp页面中调用js函数来播放具有“ divSuccess ”的页面的DOM?

Are there other ways to do this? 还有其他方法吗?

The two pages do not talk. 两页不说话。

You could send AJAX request to get content of ImprimirRelatorio.aspx page. 您可以发送AJAX请求以获取ImprimirRelatorio.aspx页面的内容。 In success handler you could parse response to get inner HTML of body tag of the ImprimirRelatorio.aspx page, set result to some container (without <iframe> ) and call Imprimir function (see details in AJAX documentation ). 在成功处理程序中,您可以解析响应以获取ImprimirRelatorio.aspx页的body标签的内部HTML,将结果设置为某个容器(不带<iframe> )并调用Imprimir函数(请参见AJAX文档中的详细信息)。 Note, the Imprimir function should be a part of success event handler of should be defined in the calling page. 注意, Imprimir函数应该是成功事件处理程序的一部分,应在调用页面中定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM