Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
hello friends...
i required in my website to open new tab whn i m clicking on button..
How to do this??
Thanks in advance..
Posted

use the following code.

Protected Sub btnReport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReport.Click
      Dim popupScript As String = "<script language="javascript">" + "window.open('Report.aspx', 'newWindow', 'left=2, top=2,location=no, width=1010, height=660, menubar=no, resizable=yes,statusbar=yes,scrollbars=yes');" + "</script>"
      Page.RegisterStartupScript("Google", popupScript)
  End Sub
 
Share this answer
 
Add this code in your button click event handler
C#
ClientScript.RegisterStartupScript(this.Page.GetType(), "",
  "window.open('somepage.aspx','Graph','height=400,width=500');", true);
 
Share this answer
 
Comments
Aysha Patel 23-Jan-13 5:21am    
What is ClientScript??
Minghang 23-Jan-13 5:35am    
in order to open your page in a new tab you need to register a client script...when your button is clicked you register the window.open() javascript function and integrate it into your page...the reason why we do this is because response.redirect function is executed at the server and the server has no way of knowing what your browser does..hence the clientscript
Member 10112214 10-Jul-13 14:39pm    
this will open d page in new window bt i want to open page in new tab....
its not that much complicated... just add a property to your asp button


OnClientClick="window.open('YourPage.aspx')"
 
Share this answer
 
v2
Hi try this

XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="jquery-1.10.2.js" type="text/javascript"></script>
    <title></title>
    <script type="text/javascript">

        function opentab() {
            window.open('http://www.codeproject.com/Questions/532873/Howplustopluscodeplustoplusopenplusnewplustabplusi');

        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Button ID="btnOpenTab" Text="Open New Tab" runat="server" OnClientClick="opentab(); return false;" />
    </form>
</body>
</html>


(or)
in server side:

C#
protected void btnOpenTab_Click(object sender, EventArgs e)
        {
            string script = " <script type=\"text/javascript\">  window.open('http://www.codeproject.com/Questions/532873/Howplustopluscodeplustoplusopenplusnewplustabplusi');   </script> ";
            //  this.Page.ClientScript.RegisterStartupScript(typeof(Page), "alert", script);
            ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", script, false);

        }



VB
<asp:Button ID="btnOpenTab" Text="Open New Tab" runat="server"
      onclick="btnOpenTab_Click"     />
 
Share this answer
 
v2
Try Only this much.....
Write down this code on button click event..

ClientScript.RegisterStartupScript(this.Page.GetType(), "", "window.open('Default.aspx');", true);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900