Tuesday, July 17, 2012

Window.open from NavigateUrl Property

Window.open in Navigate Url from code behind

Make JavaScript function in HTML

function ShowPopup(url, name, width, height) {
            window.open(url, name, 'width=' + width + ',height=' + height + ',menubar=no,status=no,statusbar=no,scrollbars=1,top=150,left=400');
        }
 
C# code behind call that function 

url = "Popup.aspx?DetID" + det.ID.ToString();
nodeDet.NavigateUrl = "javascript:ShowPopup('" + url + "','Popup'," + 800 + "," + 600 + ");";

Where url is the NavigateUrl
Popup is the name of the popup
height and width is height and width of the popup.

Hyperlink Navigate Url to window.open


<asp:HyperLink ID="HyperLink1" runat="server"
      
 NavigateUrl
="javascript:window.open('http://www.google.com','Popup','statusbar=0,toolbar=0')">
asp:HyperLink>


Response.Redirect to new window


Always get the response in new window by adding an attribute target="_blank" in form tag.
When page will do post back it will automatically open response in new window
 


html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
xmlns="http://www.w3.org/1999/xhtml">
   runat="server">
        <title>title>
    head> 
    <body> 
<form id="form1" target="_blank" runat="server">

<asp:Button ID="Button1" runat="server" Text="Button" />
form>

     body>
html>

No comments:

Post a Comment