Will VB InfoBoxes work for a web application?

52 Views Asked by At

I am using timed infoboxes to Keep the user updated as their records are inserted into the database, and am using the following Sub to create a timed infobox. It works exactly as I would like, but I am just now realizing that MessageBoxes Will not work for internet applications. I can't decide if the InfoBox Will or won't work over the internet, it seems like it probably will, but I'm really not sure. I had a horrible time trying to do Async in order to update a label. This seems by far the easiest solution if it will actually display once everything is uploaded to the server.

Sub MessageBoxTimer(curRec As String, TotalRec As String)
    Dim AckTime As Double, InfoBox As Object
    InfoBox = CreateObject("WScript.Shell")
    'Set the message box to close after 10 seconds
    AckTime = 1
    Select Case InfoBox.Popup("Updating Record " + curRec + " of " + TotalRec,
AckTime, "Scheduling all users", 1)
        Case 1, -1
            Exit Sub
    End Select
End Sub
1

There are 1 best solutions below

0
Albert D. Kallal On

You have to adopt some client side code to do this.

I suggest adopting jquery.ui dialog. So, assuming you have jQuery installed (you need that), then also install jQuery.ui.

So, when we drop a button on a form, that button can have 2 events. One that will run the server side code (a post back), and then can ALSO have a client side (JavaScript) event that also runs.

Of course if the server side code runs real fast, then that dialog will not "appear" or show for much time.

So, you could say add a "dealy" to the server side code. In fact, doing so would then NOT require a timed dialog box, since when the code behind is done, the WHOLE browser page travels back from the server, re-loads, and refresh the page.

So, let's setup a fake delay, and pop a message box while the server side code runs.

In other words we "could" setup a timed box, but when the server side code is done, the box will close anyway.

So, say this simple markup:

        <asp:Button ID="cmdStart" runat="server" 
            Text="Start the process" CssClass="btn"
            OnClick="cmdStart_Click"
            OnClientClick="mywaitdialog()"                
            />


        <div id="mywaitdialog" style="display: none" class="myshadow">
            <h3>Updating data - please wait</h3>
            <div style="text-align: center">
                <img src="../Content/wait2.gif" style="height: 64px; width: 70px" />
            </div>
        </div>

So, you can put whatever you want into that div. When you have it all nice looking, then set display:none as per above.

Now, what JQuery.UI dialog will do for you is convert htat "div" into a dialog.

so, right below above markup, we have this:

    <script>

        function mywaitdialog() {
            var myDialog = $("#mywaitdialog");
            myDialog.dialog({
                title: "Processing",
                modal: true,
                width: "350px",
            });
        }

    </script>

And my code behind for this test button example:

Protected Sub cmdStart_Click(sender As Object, e As EventArgs)

    ' fake a long process
    System.Threading.Thread.Sleep(5000)     ' 5 second delay

End Sub

and the result is now this:

enter image description here