Sunday 18 November 2012

how to use viewstate in vb.net | store value in viewstate



view state we use for using data from one function to another function  on same  .aspx page.
we can also use session but it would create burden on server .
because ViewState is client side state management so , after use once it would be destroyed.
won't create burden on server.
we can use same type of idea in c# and vb.net . so , even syntax is same.
    ViewState("definevaluewherewewanttostoreviewstatevalue") = thevaluewewanttostore

    Protected Sub buttonbind_Click(ByVal sender As Object, ByVal e As EventArgs) Handles buttonbind.Click
        Dim sql As String = "select * from stud"
        Dim cmd As SqlCommand = New SqlCommand(sql, con)
        Dim da As New SqlDataAdapter(cmd)
        Dim dt As New DataTable
        da.Fill(dt)
        Dim ds As New DataSet
        ds.Tables.Add(dt)
        Dim sql1 As String = "select * from stud where id=1"
        Dim cmd1 As SqlCommand = New SqlCommand(sql1, con)
        Dim da1 As New SqlDataAdapter(cmd1)
        Dim dt1 As New DataTable
        da1.Fill(dt1)
        ds.Tables.Add(dt1)
        ViewState("ds") = ds  'storing dataset values into ds variable.

    End Sub

    Protected Sub buttondiaplsy_Click(ByVal sender As Object, ByVal e As EventArgs) Handles buttondiaplsy.Click
        Dim dsdisplay As New DataSet
        dsdisplay = ViewState("ds") 'storing ds variable value onto another variable in another buttonclick event.

    End Sub
Share This
Previous Post
Next Post

FYJC XI standard online admisson Process and declaraton of Merit list . Cut off List For prevous year also . 10 Th Results onlne declaraton Maharashtra Region .

0 comments: