I've got a web page from which I'm spawning a pop-up with a response object to create/download a vcard. It functions as expected, but the font size on my parent page becomes huge, and only reverts back to its original when I refresh the page. How do I fix that?
My call to the vcard popup:
Response.Write(@"<script language = 'Javascript'>var" +
@" win=window.open('vCard.aspx',null,'width=50,height=50," +
@"top=100,left=100','true');</script>");
Vcard creation:
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();
}
}
Using Response.Write
before the Response is fully formed and sent back to the browser will cause the string to be written to the front of the stream.
There is actually a specific method to service this need, ClientScriptManager.RegisterClientScriptBlock
:
ClientScript.RegisterClientScriptBlock(this.GetType(), "scriptKeyNameCanBeAnythingYouWant", "var
@" win=window.open('vCard.aspx',null,'width=50,height=50," +
@"top=100,left=100','true');", true);
Reference for ClientScriptManager.RegisterClientScriptBlock
: http://msdn.microsoft.com/en-us/library/bahh2fef.aspx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.