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 |
We are using Server Intellect and have found that by far, they are the most friendly, responsive, and knowledgeable support team we've ever dealt with!
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;" End Function 'BeginAsyncOperation_connection = New SqlConnection(connectionstring) _connection.Open() _command = New SqlCommand("select title_id,title,price from titles", _connection) Return _command.BeginExecuteReader(cb, state) Sub EndAsyncOperation(ByVal ar As IAsyncResult) _reader = _command.EndExecuteReader(ar) End Sub 'EndAsyncOperationPrivate Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As EventArgs) While _reader.Read() End Sub 'Page_PreRenderComplete _reader.Read() End WhileMe.Label1.Text = Me.Label1.Text & _reader.GetValue(1) + "<br>" |
We moved our web sites to Server Intellect and have found them to be incredibly professional. Their setup is very easy and we were up and running in no time.
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> <asp:Label ID="Label1" runat="server" Text="Title: <br>"></asp:Label> </fieldset> </div> </form> </body> </html> |
Yes, it is possible to find a good web host. Sometimes it takes a while. After trying several, we went with Server Intellect and have been very happy. They are the most professional, customer service friendly and technically knowledgeable host we've found so far.
The whole code behind front page:| Imports System.Data.SqlClient Imports System.Web.Configuration Partial Class _Default Inherits System.Web.UI.Page End Class 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;" End Function 'BeginAsyncOperation_connection = New SqlConnection(connectionstring) _connection.Open() _command = New SqlCommand("select title_id,title,price from titles", _connection) Return _command.BeginExecuteReader(cb, state) 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() End Sub 'Page_PreRenderComplete _reader.Read() End WhileMe.Label1.Text = Me.Label1.Text & _reader.GetValue(1) + "<br>" Public Overrides Sub Dispose() If Not (_connection Is Nothing) Then End Sub 'Dispose_connection.Close() End IfMyBase.Dispose() Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then End SubAddHandler Me.PreRenderComplete, New EventHandler(AddressOf Page_PreRenderComplete) End IfPage.AddOnPreRenderCompleteAsync(New BeginEventHandler(AddressOf BeginAsyncOperation), New EndEventHandler(AddressOf EndAsyncOperation)) |
No comments:
Post a Comment