Run loop after page load VB.NET - asp.net

I would like the page to load, then I will display a GIF that's LOADING DATA and then I want this loop (see below) to run until the row count is not 0.
(An SQL job has been triggered in the previous page which takes about 1 - 2 minutes to run and so I want to display the new data automatically when it appears in the database.)
I can't figure out how to programmatically get this to work, I understand that because I have this in the page_load it will run before the page loads but I'm not sure how to run it after the page has loaded
Any help, advice or tips are very welcome
Thank you
Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
Do While GridView1.Rows.Count = 0 And GridView2.Rows.Count = 0
GridView1.DataBind()
GridView2.DataBind()
Loop
End Sub

If using Ajax/JQuery, can you not use a timer control that posts back every seconds and as soon as there is data in both tables then disable the timer.

Related

BackgroundWorker task blocks UI thread in my web application

Okay, I've been banging on this problem for close to 10 work hours now with no real progress to speak of. After going through multiple "solutions" offered on the web, I find myself still unable to accomplish what should be a really simple task -- pop up a modal dialog from my web application while I complete a long process I'm forcing the user to wait upon.
I've ripped out all the non-multi-threading-control aspects and am left with this bare bones structure and it still doesn't cut it:
In my ASPX file, I have two "please wait" displays, one is a DIV set up for use with bPopup, the other a DIV runat=server following the examples on BackgroundWorker. The bPopup dialog works great when used independently of any background work. But, when the background worker fires, the UI freezes until it completes, then both opens & closes the bPopup dialog as fast as it can, basically flashing the screen.
This is my code behind: I've cut it to the bare minimum to see a dialog pop up and go away again after the background task completes.
Protected Sub EditBtn_Click(sender As Object, e As EventArgs)
ScriptManager.RegisterStartupScript(Page, Page.GetType, Guid.NewGuid().ToString(), "javascript: bPopup = $('#element_to_pop_up').bPopup({ modal: true, modalClose: false});", True)
MenusBeingGenerated.Visible = True
bw = New BackgroundWorker()
bw.WorkerReportsProgress = True
bw.WorkerSupportsCancellation = True
bw.RunWorkerAsync()
End Sub
The javascript fires the bPopup, while MenusBeingGenerated is the name of the server-side DIV. The background task itself has been ripped down to just a do-nothing time-consumer.
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles bw.DoWork
For i = 1 To 40
Threading.Thread.Sleep(250)
bw.ReportProgress(i, "Running...")
If bw.CancellationPending Then
bw.ReportProgress(i, "Cancelling...")
Exit For
End If
Next
' Cleanup
If bw.CancellationPending Then
e.Cancel = True
bw.ReportProgress(100, "Cancelled.")
End If
End Sub
Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles bw.ProgressChanged
StatusLabel.Text = e.ProgressPercentage.ToString & "% complete."
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bw.RunWorkerCompleted
StatusLabel.Text = "Completed successfully"
ScriptManager.RegisterStartupScript(Page, Page.GetType, Guid.NewGuid().ToString(), "javascript: if (bPopup) { bPopup.close() };", True)
End Sub
When I run this code, and click the button that triggers it all there is a long pause then the screen blinks grey (the same behavior can be seen by opening and closing the bPopup from within the same button handler).
Adding breakpoints to walk through the code, I see the background task get launched via the button handler, it cycles through and the BackgroundWorker1_ProgressChanged handler gets called every quarter second, finally the BackgroundWorker1_RunWorkerCompleted method runs, and when that finishes the only page refresh finally happens (with the blink as bPopup fires & clears).
The DIV id=MenusBeingGenerated never displays, despite having been set as visible, nor does the label id=StatusLabel that resides within it ever get rendered.
Any clues what I've missed???
[ BTW, there are several questions along these lines on this and other web sites, none of the current answers apply. I've cookbooked this off several sites, thrown out multiple versions, and this is the closest I've gotten to something that works -- and it's no different than where I started: the user clicks the go button, a lot of nothing visible happens while the server churns out a new file, then the page refreshes when it's all done. ]

Button.Enabled and checkbox.Checked status erased when redirecting on event ASP.NET VB

In my register page I have a checkbox (chkAgree) next to the terms of agreement. The register (btnRegister) button is disabled until chkAgree.Checked = True. Since the registration section is toward the bottom of the page I want to redirect the user to an anchor tag during the event. I can't seem to accomplish this without one of the two objects in question losing their status. I tried creating a Session for each object and then calling them on the page load event with no luck. I am obviously doing it wrong, but could someone please point me in the right direction? btnRegister's default status is set to Enabled=False. Here are the two methods I am using
CheckedChanged:
Protected Sub chkAgree_CheckedChanged(sender As Object, e As EventArgs) Handles chkAgree.CheckedChanged
Session("Agree") = chkAgree.Checked
Response.Redirect("~/ExteriorStudentTestimonials.aspx#register", False)
End Sub
And Page_Load:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Session("Agree") = True Then
btnRegister.Enabled = True
chkAgree.Checked = True
Else
btnRegister.Enabled = False
chkAgree.Checked = False
End If
End Sub
I have tried several different combinations of If statements but cannot figure it out without taking Response.Redirect("~/ExteriorStudentTestimonials.aspx#register", False) out.
This might be related to the fact that you're reloading the page. You might want to take a look at the following question for some ideas of how to jump to an anchor without a full redirect: Programmatically scroll to an Anchor Tag
On a different note, jumping to an anchor when the user clicks a check box doesn't sound like a very good user experience. You might consider making your form shorter.
Got it using this method similar to the ones described in the link you provided
Page.ClientScript.RegisterStartupScript(Page.GetType(),
"navigate",
"document.getElementById('register').scrollIntoView();",
True)

Trying to read MIRC logs in ASP.net

I am trying to make a page that lets my admins read the MIRC Log files from our bot...I am having the hardest time trying to get this to work for some reason...i have taken bits and pieces of code to get what i have working...but it still either doesn't display at all OR after about 200 lines, it stops reading each line but instead make it one big mess of text...here is what i have for code
Protected Sub bView_Click(sender As Object, e As EventArgs) Handles bView.Click
Response.Write(Server.MapPath("~/mirc/logs/" & lbfiles.SelectedItem.Text))
lFileOut.Text = ""
Try
Dim FILENAME As String = Server.MapPath("~/mirc/logs/" & lbfiles.SelectedItem.Text)
Dim objStreamReader As StreamReader = New StreamReader(FILENAME, Encoding.UTF8)
Dim cont As String
Do
cont = objStreamReader.ReadLine()
lFileOut.Text = lFileOut.Text & cont & "<br>"
'Response.Write(cont)
Loop Until cont Is Nothing
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
Here is a test file i have been testing everything on...it just doesn't do anything nor does it throw any error...i am completely stumped on this one.
test file
Do this: go into your server, in your root folder make a new folder called whatever you want then go into your mIRC script goto tools/options/logging change directory to the new folder you made click save.. that way you or anyone you want to view all logs from your mIRC script can view by going to www.yoursite.net/foldername and it will show you the list of all logged things, status and room window conversations...
If you want to know how to code it so your opers can just have a clickable link in their remotes I can do that for you as well.... hope this helps

RadDatePicker in RadGrid

I'm using Telerik RadGrids and I have RadDatePickers for columns with type of DateTime. However, when I want to pick a date it doesn't work at all. No errors, but it's simply not working. I've noticed that strangely I could select more days, but I want to be able to select a single day by clicking once on the given day.
I've observed that when clicking on the previous/next month I can select a day exactly as I would like, so there is a hack which might work (in my research it worked perfectly after the first postback, but before the first postback it didn't work at all):
Public Sub PageInit(ByVal sender As Object, ByVal e As
System.EventArgs)
Me.Page.ClientScript.RegisterStartupScript(GetType(TTControls.TTAjaxState),
"Page_Init_" & Me.UniqueID, "if (!(hasEndRequest)) var hasEndRequest =
false; if (!(hasEndRequest)) {var prm =
Sys.WebForms.PageRequestManager.getInstance();prm.add_endRequest(function()
{$('.rcPrev').click();console.log('clicked');});} hasEndRequest =
true;", True)
End Sub
In the code above you can see a method which will be a handler for page init.
However, I would very much like to be able to select a day by clicking on the RadDatePicker and clicking on a day. Here is how my RadDatePicker looks like:
If anybody knows the solution and decides to share it with me (if the solution is not a hack then I would be extremely happy) I would be very gladful.
Thank you in advance,
Lajos Árpád.
Will it demand a lot of work to replace your RadDateTimePicker by a RadCalendar?
The RadCalendar supports the property SelectionMode..
Have you set the SelectionMode property to Single?
Solution:
Sys.Application.add_load(function () {
$(".RadCalendar.RadCalendar_Default .rcPrev").each(function () { $(this).click(); });
});

Can I start the Calendar Control for asp.NET to be a future date?

I need to have the Calendar Control start 36 hours after the current date. How would I do that?
I have a form that requires that the future date has to be at least 36 hours from the current date in the order for the workers involved to be able to complete the task.
EDIT: Thanks everyone for helping with my question. I've created a solution that will allow me to check values and keep the form from processing:
Protected Sub calPickupDate_SelectionChanged(sender As Object, e As System.EventArgs) Handles calPickupDate.SelectionChanged
If calPickupDate.SelectedDate < Today.AddHours(36) Then
ASPNET_MsgBox("You must leave at least 36 hours for procesing of your order.")
txtPickupDate.Text = ""
Else
txtPickupDate.Text = calPickupDate.SelectedDate.ToString("MM/dd/yyyy")
End If
End Sub
So, how do I close out the question?
Dim DateTimePicker As New DateTimePicker
DateTimePicker.MinDate = Date.Now.AddHours(36)
DateTimePicker.Value = Date.Now.AddHours(36)
add below code on your form load.
calPickupDate.MinDate = Date.Now.AddHours(36)
hope this will help you.
I assume you mean a date picker type of "calendar" and not a calendar. If so, you are dealing with a data validation issue.
There are different ways to validate the input. The quickest is server side only. If the user picks the wrong date, you tell him and he can pick ad nauseum until he gets a clue. Not the best UI, but it works.
Since the data ends up in a textbox, you can set javaScript on the textbox to remove wrong dates and show an "error" label with a message like "date/time must be X". If you can use AJAX, there are some pretty neat samples here.

Resources