Rendering Finished ASP.net, VB.NET Loading GIF - asp.net

I have been looking hard for a solution and can not seem to find anything.
Basically I have 50,000 rows in a database that is loading up rendering on the screen but takes about 20 seconds to load.
I was wondering if you can find out when asp has finished rendering, something like this;
Protected Sub Page Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
imgLoading.Visible = True
lvBigPage.Visible = False
Dim DE As New DE()
lvBigPage.DataSource = DE.BigPage_Get()
lvBigPage.DataBind()
End Sub
Private Sub lvBigPage_RenderingComplete(sender As Object, e As ListViewItemEventArgs) Handles lvBigPage.RenderingComplete
imgLoading.Visible = false
lvBigPage.Visible = True
End Sub
Using this I will be able to make some sort of load ajax gif until the page is loaded.

Related

How can I place a pause in an ASP.NET Web Application during page rendering to wait for a sub containing a SQL query to complete execution?

I have an ASP.NET application that works fine on the deployed server, but when I run it from a remote development computer connected to the production database, it displays the error: "Object reference not set to an instance of an object," which I assume is due to the SQL query used to populate some combo boxes, or perhaps the main sub populating the grid, not returning in time for the entire page to finish rendering.
These are the subs with SQL queries: FillGridOnLoad(), FillAseguradoraDropdownList() and FillDoctorDropdownList()
I'm guessing that introducing a pause in the page rendering to wait for all those subs with SQL queries to complete might solve the problem. Does that make sense? In that case, where is the wait to be inserted?
Partial Class all orders
Inherits System.Web.UI.Page
Protected Sub gridOrdenes_PageIndexChanged(sender As Object, e As EventArgs) Handles gridOrdenes.PageIndexChanged
gridOrdenes.AllowPaging = True
End Sub
Protected Sub gridOrdenes_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles gridOrdenes.PageIndexChanging
gridOrdenes.PageIndex = e.NewPageIndex
FillGridOnLoad()
End Sub
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
'...some code for authentication, etc... and then the following is the last part of the code:
If Not IsPostBack Then
FillGridOnLoad()
'Se llena el dropdown de laboratorios
Dim laboratorios As New laboratorios
dropLaboratorio.DataSource = laboratorios.fetch_all()
dropLaboratorio.DataTextField = "laboratorio"
dropLaboratorio.DataValueField = "idLaboratorio"
dropLaboratorio.DataBind()
dropLaboratorio.Items.Insert(0, "")
FillAseguradoraDropdownList()
FillDoctorDropdownList()
End If
End Sub

VB.NET display label text only on default.aspx page only

Have a message that currently displays on every page of our website. I'd like to change this so that it only appears on the homepage which is default.aspx. Please let me know what I can try. the below code lives in the code behind of the master page of the site. We use vb.net but if someone can write it in C# I can convert it.
Previous code that displays label text on every page:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Using ds As DataSet = SystemDataObject.SystemDataGetMessage()
lblSystemMessage.Text = ds.Tables(0).Rows(0)("SystemMessage_sd").ToString
End Using
End Sub
Code I have written that isn't working, what am I missing?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Using ds As DataSet = SystemDataObject.SystemDataGetMessage()
Dim appPath As String = Request.PhysicalApplicationPath
If appPath = "/Default.aspx" Then
lblSystemMessage.Text = ds.Tables(0).Rows(0)("SystemMessage_sd").ToString
End If
End Using
End Sub
Ended up wrapping the control in a panel with ID of Message and using the following code to display only if on the homepage.
If Page.Title = "Home" Then
Message.Visible = True
Else
Message.Visible = False
End If

Reader wont read on Page Load, but does when its method is called regularly

On my page I have this button, which calls this method, it works. However, when I set that same method, to be called during Page Load it works, but not completely. The method has a few readers, they read from the database and show the information, there's no issue when the method is ran reguarly, but on Page Load the readers never read.
This is one my select statements that fuel the reader:
sql.CommandText = "select temp from forecast where zone='" + myzone + "' and date=TO_DATE('" + mydate + "','dd/mm/yyyy') order by zone,date,time"
sql.CommandType = CommandType.Text
reader = sql.ExecuteReader()
Dim x As Integer
While (reader.Read())
data(0, x) = reader.Item("temp").ToString()
x += 1
End While
Again, when ran as a button click once the page is loaded it reads, when ran during Page Load it doesn't read.
It cannot be the select statement since the same exact statement works when the button is clicked. Also both variables are working and have the values they should when the statement is executed during Page Load so it can't be that either. Also tried with both Load and Init and none will work.
My Button Click:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.myMethod()
End Sub
And the Page Load:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.myMethod()
End Sub
Any ideas of what I may be doing wrong? Thanks!

BackgroundWorker – Waiting for it to finish or a timeout elapses

I have a web page which is made up of a form for data entry and a panel for displaying the results. This page is written in VB.Net and the website hosting it is in ASP.Net.
Normal usage of the page is as follows:
The user inputs the form with some data/filters
The user presses the button "Search"
A BackgroundWorker starts finding the solutions
The BackgroundWorker instance is stored in a static variable, as I don't care about multi-user scenarios, but I'm not tied to this choice and I can change this. Also, the search process is asynchronous, but I really don't need to display anything while it's in progess.
The BackgroundWorker stores the result in a SolutionStorage object.
My goal is the following.
When the BackgroundWorker ends, the solutions found must be shown on the page. However, if after a fixed amount of time (currently, three minutes) it's still running, I want to terminate it and display the solutions present in the SolutionStorage in that moment.
The code goes as follows.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsNothing(worker) Then
worker.CancelAsync()
End If
worker = New BackgroundWorker()
worker.WorkerReportsProgress = False
worker.WorkerSupportsCancellation = True
AddHandler worker.DoWork, AddressOf workerDo
AddHandler worker.RunWorkerCompleted, AddressOf workerComplete
End Sub
Protected Sub search(ByVal sender As Object, ByVal e As EventArgs) Handles submitButton.Click
worker.RunWorkerAsync()
Thread.Sleep(180 * 1000)
If worker.IsBusy Then
worker.CancelAsync()
Dim solutions = repository.getSolutions()
'' Display solutions
If (solutions.Count > 0) Then
SolutionsRepeater.DataBind()
End If
End If
End Sub
Protected Sub workerDo()
' Collect data from the form
' Build the SolutionStorage
' Start the search
End Sub
Protected Sub workerComplete(sender As Object, e As RunWorkerCompletedEventArgs)
'' Display solutions
If (solutions.Count > 0) Then
SolutionsRepeater.DataBind()
End If
End sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsNothing(worker) Then
worker.CancelAsync()
End If
worker = New BackgroundWorker()
worker.WorkerReportsProgress = False
worker.WorkerSupportsCancellation = True
AddHandler worker.DoWork, AddressOf workerDo
AddHandler worker.RunWorkerCompleted, AddressOf workerComplete
End Sub
Is this a correct way of doing things? Is this the better way of doing things?
Locking down an asp .net thread with a sleep call for 3 minutes is not a very good solution.
I would recommend you to build a background system that could do search in the background so your asp .net pages returns immediately. Then you could refresh your page every 10 seconds to
see if the search is still running, finish or failed.
Here is a little trick you might be able to use, but it has some limitations and warnings:
https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/
Read the comments to see the warnings and limitations.
But since you don't care about multi user support, and I assume the number of visits to your page is very limited, I can't see a direct problem with your current solution. But as soon as you expand it, it might cause you some problems.

client side script for treeview events

I have a Treeview with "populateOnDemand" set to true. I want this treeview to keep its state (nodes expanded/collapsed) from one page to another. Viewstate doesn't work because the treeview is different for each page. Here is my code at the moment.
ASPX page :
<asp:TreeView
ID="arbre"
EnableViewState="true"
PopulateNodesFromClient="true"
runat="server" />
Code behind :
Protected Sub arbre_TreeNodeCollapsed(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles arbre.TreeNodeCollapsed
CType(Session("listeNoeudsOuverts"), Hashtable)(e.Node.Value) = True
End Sub
Protected Sub arbre_TreeNodeExpanded(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles arbre.TreeNodeExpanded
CType(Session("listeNoeudsOuverts"), Hashtable)(e.Node.Value) = False
End Sub
Protected Sub arbre_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles arbre.TreeNodePopulate
// code to populate nodes
CType(Session("listeNoeudsOuverts"), Hashtable)(e.Node.Value) = True
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("listeNoeudsOuverts") Is Nothing Then
Session("listeNoeudsOuverts") = New Hashtable()
End If
// other stuff
End Sub
This works well, buf I wish I could avoid the postback everytime the user expands or collapses a node. I know I can set EnebleClientScript to true and manage the events client side in Javascript but I won't be able to use my session variable anymore. Is there a way to achieve this ?
Thank you
I will answer myself to a certain extent.
I've done some tests and research, EnableClientScript is true by default, and indeed means that expand and collapse actions are processed client side, by Javascript code that is automaticalt generated by the .Net framework. You can't edit it.
Apparently, if you need to add custom actions when a user expands or collapses anode, you have to use TreeNodeExpanded and TreeNodeCollapsed events, like i did above, and can't avoid postbacks because they are triggered server-side.

Resources