gpt4 book ai didi

c# - 使用响应对象创建子页面弹出窗口会破坏父页面的格式

转载 作者:行者123 更新时间:2023-11-28 02:29:41 25 4
gpt4 key购买 nike

我有一个网页,从中生成一个带有响应对象的弹出窗口,以创建/下载电子名片。它按预期工作,但是我的父页面上的字体大小变得很大,并且只有当我刷新页面时才恢复到原始状态。我该如何解决这个问题?

我对 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();
}
}

最佳答案

在响应完全形成并发送回浏览器之前使用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);

引用ClientScriptManager.RegisterClientScriptBlock:http://msdn.microsoft.com/en-us/library/bahh2fef.aspx

关于c# - 使用响应对象创建子页面弹出窗口会破坏父页面的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14420862/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com