各位兄弟姐妹:我从上周一直到现在一直想用dsoframer调用服务器上的word文档(数据库中只有文件名),但前台(aspx)中的打开word文档函数需要指定文档名称,我在后台获取了文件名,怎么才能在前台调用这个变量的值(文档名称)呢?
也就是前台javascript方法中如何调用后台的变量,谢谢了

解决方案 »

  1.   

    <object id="MyOffice" name = "MyOffice" style="LEFT: 0px; WIDTH: 100%; TOP: 0px; HEIGHT: 100%" classid="clsid:00460182-9E5E-11D5-B7C8-B8269041DD57" codebase="dsoframer.ocx#version=2,2,0,0">
     </object>
    document.all. MyOffice.Open(<%=s%>,false,"");
    public string s="";
    dsoframer
      

  2.   

    后台声明一个public string url
    再page_load事件中给url赋值前台js代码中 var m='<%=url%>'
     
      

  3.   

    这是我的前台代码
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="DispWord.aspx.cs" Inherits="DispWord" %><!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>
       <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <SCRIPT language="javascript" event="NotifyCtrlReady" for="FramerControl1">

               function OpenHelpDoc()
                {
                            document.all.FramerControl1.Open("Http://211.83.215.87/dsoframer/ModelFile/Help.doc", true);            }
                OpenHelpDoc();
    </SCRIPT>
    <script language="javascript">
    function OpenDoc(){
                    var m=' <%=url%>'
                    document.all.FramerControl1.Open( <%=m%>,false,"Word.Document"); 
            }
            </script>
    </head>
    <body onload="OpenDoc();">
        <form id="form1" runat="server">
        <div>
            <div style="text-align: center">
                <table border="0" cellpadding="0" cellspacing="0" style="width: 750px">
                    <tr>
                        <td style="width: 100px; height: 18px">
                            <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/dsoframer_down.rar" Width="280px" Font-Size="Small">点击此处下载文档在线编辑控件</asp:HyperLink></td><td align="left">
                            <asp:Label ID="Label1" runat="server" ForeColor="Red" Text="下载后用winrar解压,并点击文件夹里的Reg.bat" Width="332px" Font-Size="Small"></asp:Label></td>
                    </tr>
                    
                    <tr>
                        <td colspan="2" style="height: 431px">
                        <OBJECT id="FramerControl1" codeBase="dsoframer.ocx" height="100%" width="99%" classid="clsid:00460182-9E5E-11D5-B7C8-B8269041DD57">
                                <PARAM NAME="_ExtentX" VALUE="16960">
                                <PARAM NAME="_ExtentY" VALUE="13600">
                                <PARAM NAME="BorderColor" VALUE="-2147483632">
                                <PARAM NAME="BackColor" VALUE="-2147483643">
                                <PARAM NAME="ForeColor" VALUE="-2147483640">
                                <PARAM NAME="TitlebarColor" VALUE="-2147483635">
                                <PARAM NAME="TitlebarTextColor" VALUE="-2147483634">
                                <PARAM NAME="BorderStyle" VALUE="1">
                                <PARAM NAME="Titlebar" VALUE="0">
                                <PARAM NAME="Toolbars" VALUE="1">
                                <PARAM NAME="Menubar" VALUE="1">
                            </OBJECT>
                        </td>
                    </tr>
                </table>
            </div>
        
        </div>
        </form>
    </body>
    </html>
    这是我的后台代码:
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    ////using WordApp = Microsoft.Office.Interop.Word;
    using System.IO;
    using Microsoft.Office.Interop.Word;
    using Office = Microsoft.Office;
    using Word = Microsoft.Office.Interop.Word;
    using System.Data.SqlTypes;
    public partial class DispWord : System.Web.UI.Page
    {
        protected SqlConnection myConn;
        public string url;
        protected string Page_Load(object sender, EventArgs e)
        {
            string ID = Request["id"].ToString();
            //Response.Write("-" + ID);
            myConn = DBClass.GetConnection();
            string sqls = "select * from DBDocumentManage where 编号=" + ID;
            SqlCommand com = new SqlCommand(sqls, myConn);
            SqlDataAdapter myda = new SqlDataAdapter(sqls, myConn);
            DataSet ds = new DataSet();
            myConn.Open();
            myda.Fill(ds, "DBDocumentManage");
            DataRowView mydrv = ds.Tables["DBDocumentManage"].DefaultView[0];
            //GridView1.DataSource = ds;
            //GridView1.DataBind();        //Response.Write("<script language=javascript>windows.open('E:\\DocumentManger\\UpLoad\\1党群工作-02工会\\教职工代表大会实施细则.doc')</script>");
            string txtYJM = Convert.ToString(mydrv.Row["码一"]);
            string txtYJLMC = Convert.ToString(mydrv.Row["一级类名称"]);
            string txtEJM = Convert.ToString(mydrv.Row["码二"]);
            string txtEJLMC = Convert.ToString(mydrv.Row["二级类名称"]);
            string txtTJM = Convert.ToString(mydrv.Row["码三"]);
            string txtTJLMC = Convert.ToString(mydrv.Row["三级类名称"]);
            string txtGZZDMC = Convert.ToString(mydrv.Row["文档名称"]);
            string url = txtYJM + txtYJLMC + "-" + txtEJM + txtEJLMC + "-" + txtTJM + txtTJLMC + "/" + txtGZZDMC;
            return (url);
           
        }
    }
    我该怎么办啊,愁死我了
      

  4.   


       var id = "http://localhost/Getdc.aspx?id='602C1B35-1371-410A-A55E-0306FF3C34A4'";
       document.all.MyOffice.Open(id, false, "Word.Document");
    执行报错啊 ,有没有提示下这个地方怎么搞定它!