C# open link in new window

Hello,

I currently have a link button on my website.  when this link button is clicked I have to check certin thing that are related to that button,  then I set a url that I want it to go to.  I need that to open in a different window.  I have attached the code that I am using to do this.  There is just one problem, it makes all the font on the page when i clicked the link huge.  Any ideas whats going on?
Response.Write("<script>window.open('" + url + "');</script>");

Open in new window

LVL 1
DB_FuryAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
> it makes all the font on the page when i clicked the link huge
you mean, on the opened page?
  => the page is not coded correctly, I would say
or on the page that has the link?
  => you must have some other script doing some changes on the page
0
DB_FuryAuthor Commented:
> it makes all the font on the page when i clicked the link huge

I should have re-read what I wrote.  I ment....When I am on the page in question, I click a link and another window will popup, it works fine but after i click the link, the page the link is on, all of the font gets big, if i refresh the page where the font is big it will go back to normal.
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
is that only happening on that page/link, or on any page/link?
is that page "online" (aka can you give a link to it)?
or can you attach the resulting html of the page?
can you build a reduced test page to reproduce the problem?
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Todd GerbertIT ConsultantCommented:
Try this instead.
Using Response.Write causes your <script></script> block to occur before the <html> tag which is technically invalid HTML and may be interfering with other HTML/CSS elements on your page, e.g.:
<script>window.open('http://www.google.com/')</script>
<html><head><title>Test Page</title></head>
<body>
<form>...

Using ClientScript.RegisterStartupScript causes the <script> block to be output just before the closing tag of the <form>

ClientScript.RegisterStartupScript(this.GetType(), "newPage", "<script>window.open('http://www.google.com/');</script>");

Open in new window

0
guru_samiCommented:
instead of doing response.write....register the script like shown here:
http://dotnetslackers.com/articles/aspnet/JavaScript_with_ASP_NET_2_0_Pages_Part1.aspx#s6
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DB_FuryAuthor Commented:
oh yeah, thanks
0
DB_FuryAuthor Commented:
it works Wizard, but for some reason i have to click on the link twice when i first come to the page.  the first time I see something happens on the status bar, and the second time it will load it.  any idea why
0
guru_samiCommented:
hmm can you post some code...
0
DB_FuryAuthor Commented:
I wonder if there is something wrong with this?
lnkAnnualReport.Attributes.Add("onclick", "Javascript:window.open('" + url + "')");

Open in new window

0
guru_samiCommented:
do not use onclick attribute ...try to inject the code shown under "injecting script"
0
DB_FuryAuthor Commented:
sorry, but whay do you mean by the following :


try to inject the code shown under "injecting script"
0
DB_FuryAuthor Commented:
oh you ment in the link you sent me! Thanks very much for your help guru_sami
0
guru_samiCommented:
so did you get it working or no ?
0
DB_FuryAuthor Commented:
no, i did the following but when i click on the link button i have the following in the click even and it dosnt do anything when clicked now

       System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("<script language='javascript>'>");
        sb.Append("window.open('" + url.ToString() + "');<");
        sb.Append("/script>");
protected void lnkAnnualReport_Click(object sender, EventArgs e)
    {
        
        string Selected_Hnum = Globals.hnum;
        string Selected_HospitalName = Globals.hname;

        GetAnnualCheckBoxInformation(Selected_Hnum, Globals.Report_Year);
        string url = "www.google.com";
        //lnkAnnualReport.Attributes.Add("injecting script", "Javascript:window.open('" + url + "')");
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("<script language='javascript>'>");
        sb.Append("window.open('" + url.ToString() + "');<");
        sb.Append("/script>");

    }

Open in new window

0
DB_FuryAuthor Commented:
i think im supposed to register the client script:  something like what tgerbert said:

ClientScript.RegisterStartupScript(this.GetType(), "newPage", "<script>window.open('http://www.google.com/');</script>");


but visual studion 2008 isnt recoginizing it
0
DB_FuryAuthor Commented:
I finally got it:.   thanks
Page.ClientScript.RegisterStartupScript(this.GetType(), "newPage", "<script>window.open('" + url + "');</script>");

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.