Introduction: In this article today I am going to explain Querystring in asp.net with example
In the previous article I have explained Sql commands and its types, Format the emails using StringBulider in asp.net, Explain cookies in asp.net OR Explain cookies with example in asp.net and Get, insert, update and delete the data using one stored procedure in Sql server
Querystring is a way to passing data from one page to another page through the URL. Data that is append to end of a page URL. We pass the information from one page and on another page can retrieve it.
1. It is supported by all browsers.
2. Querystring is easy to use.
3. Server resources are not required.
4. Extra afford are not needed to code.
1. All information is visible to user. Therefore, it is not secure.
2. There is a limit to URL length of 255 characters.
I have added two webforms to project. One page has textbox and button control. I want to pass the textbox enter value to next page on button click.
HTML markup of First page:
<tr><td>Book Name:</td><td> <asp:TextBox ID="txtname" runat="server"></asp:TextBox></td></tr>
<tr><td></td><td><asp:Button ID="btnsend" runat="server" Text="Send" onclick="Button1_Click" /></td></tr>
On button click write the given code (C#):
protected void Button1_Click(object sender, EventArgs e)
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles btnsend.Click
Response.Redirect("webform2.aspx?bname=" + txtname.Text)
Html Markup of Second page where get the value:
<tr><td>Book Name:</td><td><asp:Label ID="lblbname" runat="server" Text=""></asp:Label></td></tr>
Write the below given code to get the value (C#):
protected void Page_Load(object sender, EventArgs e)
lblbname.Text = Request.QueryString["bname"];
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
lblbname.Text = Request.QueryString("bname").ToString()
If yes post your comment to appreciate my work and fell free to contact me. You can like me on Facebook, Google+, Linkedin and Twitter via hit on Follow us Button and also can get update follow by Email.
What do you think about this article?
If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.