In this Post I will explain how to open page a new window
using Jscript in Asp.Net.
Description:-
You have seen in various website when you click on link , it open the page in new window. Here I have
used a javaScript code to open new window in Asp.Net and many article
related to jquery and javaScript.
JavaScript code:-
<script type="text/javascript">
function
openWindowPopUp() {
var
popUpUrl = 'PopUpWindow.aspx?fn=' +
document.getElementById('<%= lblFirstName.ClientID %>').innerHTML
+'&ln'+ document.getElementById('<%=
lblLastName.ClientID %>').innerHTML;
var
name = 'popUp';
var
appearence = 'dependent=yes,menubar=no,resizable=no,'
+
'status=no,toolbar=no,' +
'left=5,top=280,width=230px,height=200px';
var
openNewWindow = window.open(popUpUrl, name, appearence);
openNewWindow.focus();
}
</script>
Design Page code:-
Create a Default.aspx page and write the following code
which is given below.
Default.aspx:-
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script
type="text/javascript">
function
openWindowPopUp() {
var
popUpUrl = 'NewPopUpWindow.aspx?fn=' +
document.getElementById('<%= lblFirstName.ClientID %>').innerHTML
+'&ln'+ document.getElementById('<%=
lblLastName.ClientID %>').innerHTML;
var
name = 'popUp';
var
appearence = 'dependent=yes,menubar=no,resizable=no,'
+
'status=no,toolbar=no,' +
'left=5,top=280,width=230px,height=200px';
var
openNewWindow = window.open(popUpUrl, name, appearence);
openNewWindow.focus();
}
</script>
</head>
<body>
<form
id="form1"
runat="server">
<div>
First Name:<asp:Label ID="lblFirstName"
runat="server"
Text="Label"></asp:Label><asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox><br />
Last Name:<asp:Label ID="lblLastName"
runat="server"
Text="Label"></asp:Label><asp:TextBox
ID="TextBox2" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1"
runat="server"
Text="Button" />
</div>
</form>
</body>
</html>
Write code behind page for Default.aspx .
Default.aspx.cs:-
using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
public partial class Default : System.Web.UI.Page
{
protected void
Page_Load(object sender, EventArgs e)
{
string updateValue = @"function update(popvalues)
{
document.getElementById().innerHTNL=popvalues[0];
document.getElementById().innerHTNL=popvalues[1];
}";
this.ClientScript.RegisterStartupScript(Page.GetType(),
"updateValue",
updateValue.ToString(), true);
Button1.Attributes.Add("onclick",
"openWindowPopUp('NewPopUpWindow.aspx')");
}
}
After that create second page which will be populate when
you click on button1.
NewPopUpWindow.aspx:-
<body>
<form
id="form1"
runat="server">
<div>
First Name:<asp:Label ID="lblFirstName"
runat="server"
Text="Label"></asp:Label><asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox><br />
Last Name:<asp:Label ID="lblLastName"
runat="server"
Text="Label"></asp:Label><asp:TextBox
ID="TextBox2" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1"
runat="server"
Text="Button" />
</div>
</form>
</body>
Debug code and Run.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.