How to Use QueryString in Asp.Net
QueryString in Asp.Net:-
For passing variables content from PAGE A > PAGE B in ASP.NET gives us several choices. One of the choice from all of that is using QueryString.
- A query string is additional string that is appended at the end of page link.
- Query strings fulfill our limited needs to maintain state information.
- Never rely on query strings to convey important or sensitive data, because data can be tampered by a user at any point.
To demonstrate querystring here we take two aspx pages. Let them call Page 1 and Page2.
Page 1 Code:-
01 | <%@ Page Language="C#" %> |
03 | < script runat = "server" > |
04 | protected void querystring_Click(object sender, EventArgs e) |
06 | Response.Redirect("Page 2.aspx?pid="+txtboxid.Text); |
10 | < head runat = "server" > < title >Page 1</ title > </ head > |
11 | < body > < form id = "form1" runat = "server" > < div > |
12 | < asp:TextBox ID = "txtboxid" runat = "server" ></ asp:TextBox > |
13 | < asp:Button ID = "querystring" runat = "server" Text = "Transfer Data" onclick = "querystring_Click" /> |
Page 2 Code:-
01 | <%@ Page Language="C#" %> |
03 | < script runat = "server" > |
04 | protected void Page_Load(object sender, EventArgs e) |
05 | { string pid_1 = Request.QueryString["pid"].ToString(); |
13 | < body > < form id = "form1" runat = "server" > < div > </ div > </ form > </ body > |
Now enjoy……