Querystring

0 comments
Query string is used to Pass the values or information form one page to another page.Query strings are also generated by form submission, or by a user typing a query into the address bar of the browser.
Syntax


Request.QueryString(variable)[(index)|.Count]


Parameters
variable :-


Specifies the name of the variable in the http query string to retrieve. 


index :-


An optional parameter that enables you to retrieve one of multiple values for variable. It can be any integer value in the range 1 to Request.QueryString(variable).Count. 


For example:-
In page 1:

Drag and drop the one textbox and button control 

In page 2:

Drag and drop the one textbox control from tool box and place it on form.

In page one:-

Partial Class _Default  Inherits System.Web.UI.Page
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
     'bind the textbox values to querystring
        Response.Redirect("Default2.aspx?Textboxvalue=" & TextBox1.Text)
    End Sub
End Class

In page two:-

Partial Class Default2   Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Get the values from Query string
        TextBox1.Text = Request.QueryString("Textboxvalue")
    End Sub
End Class

Disadvantages of this approach

1.QueryString have a max length, If you have to send a lot information this approach does not work.
2.QueryString is visible in your address part of your browser so you should not use it with sensitive information.
3.QueryString can not be used to send & and space characters.



























































































































































































0 comments: