In the previous chapter we study how QueryString transfer variable from one page to another page through URL using C# code. In this chapter we will study how to use QueryString through JavaScript to transfer data.
z-test.aspx
z-test2.aspx
z-test2.aspx.cs
Now Run the z-test.aspx and eneter "Mark" in name textbox and mark@gmail.com in email textbox After click on button on "go to Another Page" new window will open with output.
Example 2
z-test.aspx
z-test.aspx.cs
z-test2.aspx
z-test.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="z-test.aspx.cs" Inherits="AspDotNets.z_test" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function OpenNewWindowPart57() {
var Name = document.getElementById("txtName").value;
var Email = document.getElementById("txtEmail").value;
window.open('z-test2.aspx?UserName=' + Name + '&EmailId=' + Email, '_blank', 'location=no,resizable=no', true); //true means not maintain the history if false than maintain history
}
</script>
</head>
<body>
<form id="form1" runat="server">
Name:<asp:TextBox ID="txtName" runat="server"></asp:TextBox><br />
Email:<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox><br />
<input id="btnPart57B" onclick="OpenNewWindowPart57()" type="button" value="Window Open using Html Button"/><br />
<!--or-->
<!--<asp:Button ID="btn" runat="server" OnClientClick="OpenNewWindowPart57()" Text="Window Open using Asp.Net Button"/><br />-->
</form>
</body>
</html>
z-test2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="z-test2.aspx.cs" Inherits="AspDotNets.z_test2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
Name:-<asp:Label ID="lblName" runat="server"></asp:Label><br />
EmailId:-<asp:Label ID="lblEmail" runat="server"></asp:Label><br />
</form>
</body>
</html>
z-test2.aspx.cs
using System;
namespace AspDotNets
{
public partial class z_test2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblName.Text = Request.QueryString["UserName"];
lblEmail.Text = Request.QueryString["EmailId"];
}
}
}
Now Run the z-test.aspx and eneter "Mark" in name textbox and mark@gmail.com in email textbox After click on button on "go to Another Page" new window will open with output.
Example 2
z-test.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="z-test.aspx.cs" Inherits="AspDotNets.z_test" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
Name:<asp:TextBox ID="txtName" runat="server"></asp:TextBox><br />
Email:<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox><br />
<asp:Button ID="btnSubmit" runat="server" Text="Window Open using Asp.NEt Button" OnClick="btnSubmit_Click"/><br />
</form>
</body>
</html>
z-test.aspx.cs
using System;
namespace AspDotNets
{
public partial class z_test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string StrJavaScript = "";
Response.Write(StrJavaScript);
}
}
}
z-test2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="z-test2.aspx.cs" Inherits="AspDotNets.z_test2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
Name:-<asp:Label ID="lblName" runat="server"></asp:Label><br />
EmailId:-<asp:Label ID="lblEmail" runat="server"></asp:Label><br />
</form>
</body>
</html>
using System;
namespace AspDotNets
{
public partial class z_test2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblName.Text = Request.QueryString["UserName"];
lblEmail.Text = Request.QueryString["EmailId"];
}
}
}

0 comments:
Post a Comment