aspx_professional thread: Javascript 'window.open' function using LinkButton WebControl
Try this:
public void newWin(string varWindow)
{
string WinCode;
WinCode =3D "<script>window.open(\"" + varWindow
+ "\",\"newWin\",\"height=3D465, width=3D450, status=3Dno, toolbar=3Dno,
menubar=3Dno, location=3Dno\");</script>";
Response.Write(WinCode);
}
public void LB1_Click(object sender, System.EventArgs e)
{
newWin("http://www.url1.com");
}
public void LB2_Click(object sender, System.EventArgs e)
{
newWin("http://www.url2.net");
}
public void LB3_Click(object sender, System.EventArgs e)
{
newWin("http://www.url3.com");
}
You should also consider using the RegisterStartupScript method.
-----Original Message-----
From: Doug Wood [mailto:dougwood@a...]
Sent: 8. november 2002 01:24
To: ASPX_Professional
Subject: [aspx_professional] Javascript 'window.open' function using
LinkButton WebControl
I am trying to create the same effect as a client-side
javascript 'window.open' function using a LinkButton control and was
wondering if anyone has ever done this and could show me their code, or
could help with this code below:
I'll cut through all the extraneous code..
in my aspx page:
<form id=3D"LBForm" method=3D"post" runat=3D"server">
<asp:LinkButton id=3D"LB1" runat=3D"server"
OnClick=3D"LB1_Click">URL</asp:LinkButton>
<asp:LinkButton id=3D"LB2" runat=3D"server"
OnClick=3D"LB2_Click">url</asp:LinkButton>
<asp:LinkButton id=3D"LB3" runat=3D"server"
OnClick=3D"LB3_Click">url</asp:LinkButton>
</form>
and in my code-behind page I have this:
public void newWin(string varWindow)
{
string WinCode;
WinCode =3D "<script>" + "window.open(" + varWindow
+ ",'newWin'," + "height=3D465, width=3D450, status=3Dno, toolbar=3Dno,
menubar=3Dno, location=3Dno'); " + "</script>";
Response.Write(WinCode);
}
public void LB1_Click(object sender, System.EventArgs e)
{
newWin("http://www.url1.com");
}
public void LB2_Click(object sender, System.EventArgs e)
{
newWin("http://www.url2.net");
}
public void LB3_Click(object sender, System.EventArgs e)
{
newWin("http://www.url3.com");
}
When I build the solution, I receive no errors, but once I view in a
browser and actually click on any of the links, I get a 'Internet
Explorer
Script Error' which says 'Unterminated string constant' .
Can anyone help me troubleshoot this?
I don't even know if this is the most effective way of doing it, so feel
free to tell me I'm doing it all wrong!
Thanks is advance!!!