我想实现用linkbutton实现和hyperlink一样的连接效果(页面自动打开,文件自动下载),点击连接存储下载记录信息,并实现连接效果。
我用了两种方法,效果都不好:
1)用linkbutton,在click事件中加了脚本代码:
存储数据;
Response.Write("<script language=javascript>window.open('" + ColumnValue[4] + "','_blank')</script>");可在xp上使用有问题,我查了一下原因,是xp本身问题:
不能使用 Window.Open 方法打开或下载一个基于 Windows XP Service Pack 2 的计算机上的一个文件
所以要避开这个方法2)用hyperlink转到数据处理页,存储数据,用response.redirect("test.asp");转向链接页面,但也有问题,我的链接页面数据是从别人的数据库以xml形式得到的,如果只传ID,需要重新查找数据,运行很慢;如果所有数据都传过来,链接地址串又会超常,而且有非法字符。
请问有什么好办法能够一点连接,能够存储点击记录的所有数据,又能很快地转向链接页面?

解决方案 »

  1.   

    用流的方式读取文件,再写出来
    用ASP写的我没有类似代码.ASP.NET的类似这样  System.IO.FileInfo file = new System.IO.FileInfo(fileName);
                if (file.Exists)
                {
                    System.IO.FileStream fs = null;
                    fs = System.IO.File.Open(fileName, System.IO.FileMode.Open);
                    byte[] btFile = new byte[fs.Length];
                    fs.Read(btFile, 0, Convert.ToInt32(fs.Length));
                    fs.Close();                System.Web.HttpContext.Current.Response.Clear();
                    System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
                    System.Web.HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
                    System.Web.HttpContext.Current.Response.ContentType = "audio/mpeg3";
                    System.Web.HttpContext.Current.Response.BinaryWrite(btFile);
                }
                else
                {
                    System.Web.HttpContext.Current.Response.Write("This file does not exist.");
                }
    具体文件类型请参照 MIME类型确定.在那代码上面操作记录
      

  2.   

    谢谢fancystyle !
    我试试,这个好像是在本页打开,我需要像链接一样在新的窗口打开。
      

  3.   

    对于fancystyle的方法,我测试了,也不能在这里使用,因为我的文件是以url格式存在,而且不是本程序虚拟目录下的地址,有的是网址,有的是文件链接(url),还有其它方法吗?或者是上面的方法改进一下?
      

  4.   

    2)用hyperlink转到数据处理页,存储数据,用response.redirect("test.asp");转向链接页面,但也有问题,我的链接页面数据是从别人的数据库以xml形式得到的,如果只传ID,需要重新查找数据,运行很慢;如果所有数据都传过来,链接地址串又会超常,而且有非法字符。 可以考虑用session传值
    数据不是很大的话也可以用cookie
      

  5.   

    第一个问题,以后再不要用Response.Write输出JavaScript了
    第二个问题,表单提交方式改成Post
      

  6.   

    用hyperlink转到数据处理页,存储数据,用response.redirect("test.asp");
    -----------------------
    非要转到test.asp存储数据吗?在本页处理,把数据存入session,再转页,这个页就不用重新搜了,直接session里取
      

  7.   

    请问百度中是怎么用脚本向服务器写数据的,我要实现的功能和百度搜索链接的效果差不多,点击链接,保存数据,打开链接;如下面百度代码的onmousedown事件,我想不明白客户脚本怎么向数据库写数据
    <a href="http://www.onejoo.com:8000/" target=_blank class=l onmousedown="return clk(0,'','','res','4','')"><font color=CC0033>玩聚</font>
      

  8.   

    yanrabbit163 能说的具体点吗?我对ajax调WebService不是很熟。
    最好有个现成的例子,谢谢!
      

  9.   


    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Debug">
    <Services>
    <asp:ServiceReference Path="WebServiceFoundation.asmx" InlineScript="true" />
    </Services>
    </asp:ScriptManager>

    <input type="button" value="Get Random" onclick="getRandom()" />
    <input type="button" value="Get Range Random" onclick="getRandom(0, 9)" />

    <script language="javascript" type="text/javascript">
    function getRandom(minValue, maxValue)
    {
    if (arguments.length != 2)
    {
    Sample.WebServiceFoundation.GetRandom(getRandomSucceeded);
    }
    else
    {
    Sample.WebServiceFoundation.GetRangeRandom(minValue, maxValue, getRandomSucceeded);
    }
    }

    function getRandomSucceeded(result)
    {
    alert(result);
    }
    </script>
        </form>
      

  10.   


    <%@ WebService Language="C#" Class="Sample.WebServiceFoundation" %>using System;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Web.Script.Services;namespace Sample
    {
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ScriptService]
    public class WebServiceFoundation : System.Web.Services.WebService
    {
    [WebMethod]
    public int GetRandom()
    {
    return new Random(DateTime.Now.Millisecond).Next();
    } [WebMethod]
    public int GetRangeRandom(int minValue, int maxValue)
    {
    int a = new Random(DateTime.Now.Millisecond).Next(minValue, maxValue);
                int b = new Random(DateTime.Now.Millisecond).Next(minValue, maxValue);
                int c = new Random(DateTime.Now.Millisecond).Next(minValue, maxValue);
                return a + b + c;
    }
    }
    }