Click here to Skip to main content
15,909,242 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:
hi....
can anybody tell me how we can open new window on click of button in asp.net 4.0.
thanks....note that I dont Have to used javascript..
Posted
Updated 15-Aug-11 19:03pm
v2

<%@ Page Language="C#" %>

<%@ Import namespace="System.Text" %>

<script  runat="server">

void Page_load(object sender, EventArgs e)

{

Button1.Attributes.Add( "onclick", "popWin()" );

}

</script>

<html>

<head>

<script>

function popWin()

{

window.open('yourpage.aspx");

}

</script>

</head>

<body>

<form  runat="server">

<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Go!">

</form>

</body>

</html>


or we can try this


Page load. (C#)

protected void Page_Load(object sender, EventArgs e)
     {
       if (!IsPostBack)
       {
         string url = "yourpage_to_open.aspx?querystrings=23";
          
         Button1.Attributes.Add("onclick", "window.open('" + url + "', '_blank', 'height=500,width=800,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,titlebar=no' );return false;");
       }
     }

ASPX
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head  runat="server">
  <title></title>
</head>
<body>
  <form id="form1"  runat="server">
  <div>
    <asp:Button ID="Button1" runat="server" Text="Button" />
  </div>
  </form>
</body>
</html>
 
Share this answer
 
v2
Comments
nagendrathecoder 17-Aug-11 2:51am    
Format your code properly.
if you would have searched google first then you might not needed to post question here coz you gave solution urself (isn't that amazing :D )
vivek_cool 17-Aug-11 3:03am    
i think you have answer then only tell..i am not asking your suggestion
This[^] might help you out.
 
Share this answer
 
 
Share this answer
 

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