Click here to Skip to main content
13,090,417 members (61,630 online)
Click here to Skip to main content


107 bookmarked
Posted 23 Jul 2005

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

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 WebForm1
    Inherits System.Web.UI.Page

#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 LinkButton1 As System.Web.UI.WebControls.LinkButton
    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.
    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)

    End Sub

    Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
    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.


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


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.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170813.1 | Last Updated 23 Jul 2005
Article Copyright 2005 by Régis Daniel de Oliveira
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid