1

我有一个网页,我从中生成一个带有响应对象的弹出窗口,以创建/下载 vcard。它按预期运行,但是我的父页面上的字体大小变得很大,并且只有在我刷新页面时才会恢复到原来的大小。我该如何解决?

我对 vcard 弹出窗口的调用:

 Response.Write(@"<script language = 'Javascript'>var" +
                        @" win=window.open('vCard.aspx',null,'width=50,height=50," +
                        @"top=100,left=100','true');</script>");

电子名片制作:

 public static void VCard(HttpResponse response)
    {
        response.Clear();
        response.Charset = "";
        response.ContentType = "text/x-vCard";
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

            {
                response.AddHeader("content-disposition", "attachment; filename=" + usr.SamAccountName);

                stringWrite.WriteLine("BEGIN:VCARD");
                stringWrite.WriteLine("VERSION:2.1");
                //Name
                stringWrite.WriteLine("N:" + usr.LastName + ";" + usr.FirstName
                    );
               //removed other vcard lines....

                //vCard End
                stringWrite.WriteLine("END:VCARD");
                response.Write(stringWrite.ToString());
                response.End();
            }
    }
4

1 回答 1

1

Response.Write在响应完全形成并发送回浏览器之前使用将导致字符串被写入流的前面。

实际上有一种特定的方法可以满足这种需求ClientScriptManager.RegisterClientScriptBlock

ClientScript.RegisterClientScriptBlock(this.GetType(), "scriptKeyNameCanBeAnythingYouWant", "var
                    @" win=window.open('vCard.aspx',null,'width=50,height=50," +
                    @"top=100,left=100','true');", true);

参考:http ClientScriptManager.RegisterClientScriptBlock: //msdn.microsoft.com/en-us/library/bahh2fef.aspx

于 2013-01-20T02:03:32.157 回答