Interview Questions on Query Strings in ASP.NET
Give an example of using querystrings to send data from one page to another?
Query strings are a very simple and popular technique to pass data from one Web page to the next. You send data as part of the URL. In the below example FName and LName are sent as part of the URL. In the page load of QueryStrings2.aspx we use Request.QueryString to read the values. As we are sending more than one query string we use the & symbol to seperate query strings.
//Code to send query strings FName and LName as part of the URL
QueryStrings2.aspx?FName=David&LName=Boon
protected void Page_Load(object sender, EventArgs e)
{
//Code to read Query String values
string FirstName = Request.QueryString["FName"];
string LastName = Request.QueryString["LName"];
Response.Write("Data from QueryStrings1.aspx : " + FirstName + ", " + LastName);
}
Give an example to send Query Strings from code?
You can send query strings from server side code using the Response.Redirect() method as shown below.
Response.Redirect("QueryStrings2.aspx?FName=David&LName=Boon");
What are the advantages of using Query Strings?
1. Query strings are easy to implement.
2. Browser support for passing values in a query string is nearly universal.
3. Query strings are contained in the HTTP request for a specific URL and do not require server resources.
What are the disadvantages of using querystrings to send data from one page to another?
1. Query strings are insecure because the information in the query string is directly visible to the user on the address line in the browser.
2. Many browsers impose a 255 URL character limit which can limit their flexibility.
Subscribe to:
Post Comments (Atom)
Response.Redirect("QueryStrings2.aspx?FName=server.urlencode(David&Siva)");
ReplyDelete....URL encoding ensures that all browsers will correctly transmit text in URL strings. Characters such as ?, &,/, and spaces..
~Sivaprakasam
Leaving this note here for my own sake. How to urlencode a querystring parameter: Server.UrlEncode(value).
DeleteCan i pass QueryString using Server.Transfer() Methode?
ReplyDeleteServer.Transfer method doesn't update the destination page url so query string wont be visible...
DeleteServer.Transfer method doesn't update the destination page url so query string wont be visible...
Deleteyou cannot pass Querystring using Server. Transfer()Method
ReplyDeleteQueryStrings2.aspx?FName:David&LName:Boon
ReplyDeleteif we use ' : ' instead of ' = ' in above statement , in control its doesn't retaining its state .
Why its happening ?
Which scenario use the query string is best practices ?
Delete