Suggested Videos
Part 54 - Server.execute in asp.net
Part 55 - Cross page postback
Part 56 - Cross page postback strongly typed reference
The following are the different page navigation techniques in asp.net
1. Hyperlink control - Discussed in Part 13 and Part 51 of the ASP.NET video series
2. Response.Redirect - Discussed in Part 52
3. Server.Transfer - Discussed in Part 53
4. Server.Execute - Discussed in Part 54
5. Cross-Page postback - Discussed in Part 55 and Part 56
6. Window.Open
In this video we will discuss about, opening a new window using javascript method window.open(). First the syntax of the window.open() method.
window.open(URL, name, features, replace)
HTML of WebForm1.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Training Demo</title>
<script type="text/javascript">
// Javascript function to open the new window
function OpenNewWindow()
{
var Name = document.getElementById('txtName').value;
var Email = document.getElementById('txtEmail').value;
window.open('WebForm2.aspx?Name=' + Name + '&Email=' + Email, '_blank', 'toolbar=no, location=no, resizable=yes,
width=500px, height=500px', true);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="font-family: Arial">
<table>
<tr>
<td colspan="2">
<h1>
This is WebForm1</h1>
</td>
</tr>
<tr>
<td>
<b>Name</b>
</td>
<td>
:<asp:TextBox ID="txtName" runat="server">
</asp:TextBox>
</td>
</tr>
<tr>
<td>
<b>Email</b>
</td>
<td>
:<asp:TextBox ID="txtEmail" runat="server">
</asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<input id="Button1" type="button" value="HTML Input Button - Window.Open"
onclick="OpenNewWindow()" style="width: 300px"
/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="Button2" runat="server"
Text="ASP.NET Button - Window.Open()" onclick="Button2_Click"
Width="300px" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Code-Behind code for WebForm1.aspx.cs
protected void Button2_Click(object sender, EventArgs e)
{
string strJavascript = "<script type='text/javascript'>window.open('WebForm2.aspx?Name=";
strJavascript += txtName.Text + "&Email=" + txtEmail.Text + "','_blank');</script>";
Response.Write(strJavascript);
}
HTML of WebForm2.aspx
<div style="font-family: Arial">
<table>
<tr>
<td colspan="2">
<h1>This is WebForm2</h1>
</td>
</tr>
<tr>
<td>
<b>Name</b>
</td>
<td>
:<asp:Label ID="lblName" runat="server">
</asp:Label>
</td>
</tr>
<tr>
<td>
<b>Email</b>
</td>
<td>
:<asp:Label ID="lblEmail" runat="server">
</asp:Label>
</td>
</tr>
</table>
</div>
Code-Behind code for WebForm2.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
lblName.Text = Request.QueryString["Name"];
lblEmail.Text = Request.QueryString["Email"];
}
Part 54 - Server.execute in asp.net
Part 55 - Cross page postback
Part 56 - Cross page postback strongly typed reference
The following are the different page navigation techniques in asp.net
1. Hyperlink control - Discussed in Part 13 and Part 51 of the ASP.NET video series
2. Response.Redirect - Discussed in Part 52
3. Server.Transfer - Discussed in Part 53
4. Server.Execute - Discussed in Part 54
5. Cross-Page postback - Discussed in Part 55 and Part 56
6. Window.Open
In this video we will discuss about, opening a new window using javascript method window.open(). First the syntax of the window.open() method.
window.open(URL, name, features, replace)
Parameter Name | Description |
URL (Optional) | The URL of the page to open. If URL is not specified, a new window with about:blank is opened. |
Name (Optional) | Specifies the target attribute or the name of the window.
|
Features (optional) | A comma-separated list of items.
|
Replace(Optional) | A boolean parameter that specifies whether the url creates a new entry or replaces the current entry in the window's history list. This parameter only takes effect if the url is loaded into the same window.
|
HTML of WebForm1.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Training Demo</title>
<script type="text/javascript">
// Javascript function to open the new window
function OpenNewWindow()
{
var Name = document.getElementById('txtName').value;
var Email = document.getElementById('txtEmail').value;
window.open('WebForm2.aspx?Name=' + Name + '&Email=' + Email, '_blank', 'toolbar=no, location=no, resizable=yes,
width=500px, height=500px', true);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="font-family: Arial">
<table>
<tr>
<td colspan="2">
<h1>
This is WebForm1</h1>
</td>
</tr>
<tr>
<td>
<b>Name</b>
</td>
<td>
:<asp:TextBox ID="txtName" runat="server">
</asp:TextBox>
</td>
</tr>
<tr>
<td>
<b>Email</b>
</td>
<td>
:<asp:TextBox ID="txtEmail" runat="server">
</asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<input id="Button1" type="button" value="HTML Input Button - Window.Open"
onclick="OpenNewWindow()" style="width: 300px"
/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="Button2" runat="server"
Text="ASP.NET Button - Window.Open()" onclick="Button2_Click"
Width="300px" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Code-Behind code for WebForm1.aspx.cs
protected void Button2_Click(object sender, EventArgs e)
{
string strJavascript = "<script type='text/javascript'>window.open('WebForm2.aspx?Name=";
strJavascript += txtName.Text + "&Email=" + txtEmail.Text + "','_blank');</script>";
Response.Write(strJavascript);
}
HTML of WebForm2.aspx
<div style="font-family: Arial">
<table>
<tr>
<td colspan="2">
<h1>This is WebForm2</h1>
</td>
</tr>
<tr>
<td>
<b>Name</b>
</td>
<td>
:<asp:Label ID="lblName" runat="server">
</asp:Label>
</td>
</tr>
<tr>
<td>
<b>Email</b>
</td>
<td>
:<asp:Label ID="lblEmail" runat="server">
</asp:Label>
</td>
</tr>
</table>
</div>
Code-Behind code for WebForm2.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
lblName.Text = Request.QueryString["Name"];
lblEmail.Text = Request.QueryString["Email"];
}
well explained Sir
ReplyDeleteVery nice Sir, U r great. I would say more than excellent. I have watched almost all videos posted by you on youtube. Its a great help for all the students who wants to learn programming. You have helped the people in a great way. God Bless You Sir.
ReplyDelete