Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Re: Javascript 'window.open' function using LinkButton WebControl


Message #1 by "Mingkun Goh" <mangokun@h...> on Mon, 9 Dec 2002 17:57:31
Regarding opening a popup window, I did also use in some of my projects.
I hope my sample code below will be of use to you.


[MyCareer.aspx]
	<HEAD>
		<title>myCareer</title>

		<script language="JavaScript">
		<!---
			function popUp(url, WindowName) {
				window.open
(url,WindowName,'toolbar=0,location=0,directories=0,status=0,menubar=0,scro
llbars=0,resizable=0,width=screen.width,height=screen.Height,left=0,top=0')
.focus();
			}

			function popUpCenter(url, WindowName, WindowWidth, 
WindowHeight) {
				var leftpos=screen.width/2 - WindowWidth/2;
				var toppos=screen.height/2 - 
WindowHeight/2;
				window.open
(url,WindowName,'toolbar=0,location=0,directories=0,status=0,menubar=0,scro
llbars=1,resizable=1,width='+WindowWidth+',height='+WindowHeight+',left='+l
eftpos+',top='+toppos).focus();
			}
		-->
		</script>
	</HEAD>


[MyCareer.aspx.vb]
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then
            ' javascript code is added for each button's client-side 
onclick event
            Button1.Attributes.Add("onclick", "javascript:popUpCenter
('JobSearchResult.aspx','JobListing',700,600);return false;")
        End If
    End Sub



Note: JavaScript code is only needed in MyCareer.aspx if you intend to 
call the function many times.
If not, you can just put the whole "window.open(...)" string in the code-
behind.



Previous message:
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="LBForm" method="post" runat="server">

<asp:LinkButton id="LB1" runat="server" 
OnClick="LB1_Click">URL</asp:LinkButton>

<asp:LinkButton id="LB2" runat="server" 
OnClick="LB2_Click">url</asp:LinkButton>

<asp:LinkButton id="LB3" runat="server" 
OnClick="LB3_Click">url</asp:LinkButton>

</form>

and in my code-behind page I have this:

            public void newWin(string varWindow)
		{
		string WinCode;
		WinCode = "<script>" + "window.open(" + varWindow 
+ ",'newWin'," + "height=465, width=450, status=no, toolbar=no, 
menubar=no, location=no'); " + "</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!!!

  Return to Index