Querystring metoduyla Web Sayfaları Arasında Veri Göndermek
Merhaba arkadaşlar bu makalemizde querystring metoduyla web sayfaları arasında veri göndereceğiz. Projemize 2 web sayfası ekliyoruz.
Birinci web sayfasına Textbox, label ve butonlar ekliyoruz. Burada textBox a girilen verileri Butona tıklayıp, querystring metodunu kullanarak ikinci web sayfasına aktaracağız.

Şekil 1
Sonrasında ikinci web sayfasına eklediğimiz label nesnelerinde birinci sayfada girilmiş olan bu verileri göstereceğiz.

Şekil 2
WebForm1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace querystring_to_send_values
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSend_Click(object sender, EventArgs e)
{
Response.Redirect("WebForm2.aspx?PersonId=" + txtPersonId.Text + "&PersonFirstName=" + txtFirstName.Text + "&PersonLastName=" + txtLastName.Text + "&Mail=" + txtMail.Text);
}
}
}
WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="querystring_to_send_values.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Font-Size="Large" Text="Person Id: "></asp:Label>
<asp:TextBox ID="txtPersonId" runat="server" Font-Size="Large"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label2" runat="server" Font-Size="Large" Text="First Name: "></asp:Label>
<asp:TextBox ID="txtFirstName" runat="server" Font-Size="Large"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label3" runat="server" Font-Size="Large" Text="Last Name:"></asp:Label>
<asp:TextBox ID="txtLastName" runat="server" Font-Size="Large"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label4" runat="server" Font-Size="Large" Text="Mail: "></asp:Label>
<asp:TextBox ID="txtMail" runat="server" Font-Size="Large"></asp:TextBox>
<br />
<br />
<asp:Button ID="btnSend" runat="server" Font-Size="Large" Height="43px" OnClick="btnSend_Click" Text="Send" Width="230px" />
</div>
</form>
</body>
</html>
WebForm2.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace querystring_to_send_values
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblPersonId.Text = Request.QueryString["PersonId"];
lblFirstName.Text = Request.QueryString["PersonFirstName"];
lblLastName.Text = Request.QueryString["PersonLastName"];
lblMail.Text = Request.QueryString["Mail"];
}
}
}
}
WebForm2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="querystring_to_send_values.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="font-size:large">
<b>Person Id: </b><asp:Label ID="lblPersonId" runat="server" Text="Label" Font-Size="Large"></asp:Label>
<br />
<br />
<b>First Name: </b><asp:Label ID="lblFirstName" runat="server" Text="Label" Font-Size="Large"></asp:Label>
<br />
<b>
<br />
Last Name: </b><asp:Label ID="lblLastName" runat="server" Text="Label" Font-Size="Large"></asp:Label>
<br />
<b>
<br />
Mail: </b><asp:Label ID="lblMail" runat="server" Text="Label" Font-Size="Large"></asp:Label>
</div>
</form>
</body>
</html>
Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek üzere. Bahadır ŞAHİN