Saturday 11 January 2014

Different techniques to move data from one webform to another

1. Cross Page Postback

2. Context.Handler object

3. Query strings

4. Cookies

5. Session state

6. Application state

Points to remember about query strings

1. Querystrings are name/value collection pairs

2. Using querystrings, is a very comman way to send data from one webform to another.

3. Query strings are appended to the page URL.

4. ?(Question Mark), indicates the beginning of a query string and it's value.

5. It is possible to use more than one query string. The first query string is specified using the ?(question mark). Subsequent query strings can be appended to the URL using the &(ampersand) symbol.

6. There is a limit on the Query string length. Hence, Query strings cannot be used to send very long data.

7. Query strings are visible to the user, hence should not be used to send sensitive information, unless encrypted.

8. To read the query string value, use Request object's QueryString property.

9. &(ampersand) is used to concatenate query strings, so if you want to send &, as value for the query string there are 2 ways, as shown below

Using Server.UrlEncode() method

Response.Redirect("WebForm2.aspx?UserNam­e=" + Server.UrlEncode(txtName.Text) + "&UserEmail=" + Server.UrlEncode(txtEmail.Text));

Or

&(ampersand) is encoded as %26, so use, Replace() function to replace & with %26

Response.Redirect("WebForm2.aspx?UserNam­e=" + txtName.Text.Replace("&", "%26") + "&UserEmail=" + txtEmail.Text.Replace("&", "%26"));

No comments:

Post a Comment