DotNet Tutorials

Server Intellect

 Asynchronous DataShow in Asp.Net 2.0 and VB.NET

Asynchronous DataShow in Asp.Net 2.0 will improve capability of the page. This tutorial will show you how to create Asynchronous DataShow in ASP.Net 2.0 and VB.NET.

First we should add Async="true" in the <%page > code.Then we use function Page. AddOnPreRenderCompleteAsync to register a function begin and function end.we use label control to show the title of table titles.

Imports System.Data.SqlClient

Custom function BeginAsyncOperation ,EndAsyncOperation and Page_PreRenderComplete

Function BeginAsyncOperation(ByVal sender As Object, ByVal e As EventArgs, ByVal cb As AsyncCallback, ByVal state As Object) As IAsyncResult
Dim connectionstring As String = "server=localhost;uid=sa;pwd=1234;database=Pubs;Asynchronous Processing=true;"
_connection = New SqlConnection(connectionstring)
_connection.Open()

_command = New SqlCommand("select title_id,title,price from titles", _connection)
Return _command.BeginExecuteReader(cb, state)
End Function 'BeginAsyncOperation

Sub EndAsyncOperation(ByVal ar As IAsyncResult)
_reader = _command.EndExecuteReader(ar)
End Sub 'EndAsyncOperation

Private Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As EventArgs)

While _reader.Read()
_reader.Read()
Me.Label1.Text = Me.Label1.Text & _reader.GetValue(1) + "<br>"
End While
End Sub 'Page_PreRenderComplete

We used over 10 web hosting companies before we found Server Intellect. Their dedicated servers and add-ons were setup swiftly, in less than 24 hours. We were able to confirm our order over the phone. They respond to our inquiries within an hour. Server Intellect's customer support and assistance are the best we've ever experienced.


The front page of Default.aspx

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Default</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<fieldset><legend>AsyncDataBind</legend>&nbsp;&nbsp;
<asp:Label ID="Label1" runat="server" Text="Title: <br>"></asp:Label>
</fieldset>
</div>
</form>
</body>
</html>

The whole code behind front page:

Imports System.Data.SqlClient
Imports System.Web.Configuration
Partial Class _Default
Inherits System.Web.UI.Page
Private _connection As SqlConnection
Private _command As SqlCommand
Private _reader As SqlDataReader
Function BeginAsyncOperation(ByVal sender As Object, ByVal e As EventArgs, ByVal cb As AsyncCallback, ByVal state As Object) As IAsyncResult
Dim connectionstring As String = "server=localhost;uid=sa;pwd=1234;database=Pubs;Asynchronous Processing=true;"
_connection = New SqlConnection(connectionstring)
_connection.Open()

_command = New SqlCommand("select title_id,title,price from titles", _connection)
Return _command.BeginExecuteReader(cb, state)
End Function 'BeginAsyncOperation

Sub EndAsyncOperation(ByVal ar As IAsyncResult)
_reader = _command.EndExecuteReader(ar)

End Sub 'EndAsyncOperation

Private Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As EventArgs)
While _reader.Read()
_reader.Read()
Me.Label1.Text = Me.Label1.Text & _reader.GetValue(1) + "<br>"
End While
End Sub 'Page_PreRenderComplete
Public Overrides Sub Dispose()
If Not (_connection Is Nothing) Then
_connection.Close()
End If
MyBase.Dispose()
End Sub 'Dispose

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
AddHandler Me.PreRenderComplete, New EventHandler(AddressOf Page_PreRenderComplete)
Page.AddOnPreRenderCompleteAsync(New BeginEventHandler(AddressOf BeginAsyncOperation), New EndEventHandler(AddressOf EndAsyncOperation))
End If
End Sub
End Class

We migrated our web sites to Server Intellect over one weekend and the setup was so smooth that we were up and running right away. They assisted us with everything we needed to do for all of our applications. With Server Intellect's help, we were able to avoid any headaches!



Looking for the C#.NET 2005 Version? Click Here!

Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!
 
123 ASP

411 ASP

Dot Net Freaks

Server Intellect