Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

Keep ASP.NET ViewState out of ASPX Page for Performance Improvement

, 23 Jul 2005
How you could improve performance of your ASP.NET projects, keeping ViewState on the server instead of on the ASPX page.
Imports System.Data.SqlClient

Public Class WebForm2
    Inherits VSPage             '<----- Inheruted from the VSPage Class

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Dim myConnection As SqlConnection

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Put user code to initialize the page here
        myConnection = New SqlConnection(" DATABASE=Northwind;SERVER= localhost;UID=sa;PWD=password;")
        If Not Page.IsPostBack Then BindGrid()
    End Sub

    Private Sub BindGrid()

        'Create a DataAdapter to fetch data from Products Table
        Dim myCommand As SqlDataAdapter
        myCommand = New SqlDataAdapter("select * from orders WHERE ORDERID < 10600", "DATABASE=Northwind;SERVER=localhost;UID=sa;PWD=;")

        'Create a DataSet and Fills it with Product Data
        Dim ds As New DataSet
        myCommand.Fill(ds, "OrderID")

        DataGrid1.DataSource = ds.Tables(0)
        DataGrid1.DataBind()

    End Sub

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Régis Daniel de Oliveira
Web Developer
Brazil Brazil
Régis Daniel is currently living in Itaúna, MG, Brazil. He works with programming since 1999 and actualy works as IT Manager on a wholesaler company. He has experiency as Oracle DBA, and also worked as a PalmOS developer using CodeWarrior with C/C++.
Now a days he works on .NET Framework, developing solutions on Visual Basic.NET and ASP.NET. During his spare time, he likes reading books, watching movies and pratices some outdoor activities, like Trekking and Camping.

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 23 Jul 2005
Article Copyright 2005 by Régis Daniel de Oliveira
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid