View Single Post
 
Old February 17th, 2004, 08:26 AM
planoie's Avatar
planoie planoie is offline
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The label doesn't show up until the page is rendered and the page is never rendered until all your code is done processing.

What you need to do is have an intermediate view of the page that the user sees after they press the button to begin processing.

- Create another button on the form (cmdProcess)
- Use the CSS style display:none; to make cmdProcess invisible. You cannot use the .net visible property because this will cause the button to not render to the HTML. The button HTML must be in the page's HTML, but you just don't want the user to SEE it.
- Use the RegisterStartupScript() method to write out a little javascript that call's that hidden button's click() method.
- Call the startup script from the button handler the user actually clicks.
- Move the code that takes a long time to process to the new button's click handler.

<asp:button runat="server" id="cmdProcess" style="display:none;" />

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim sStartProcess As String
    lbl.Text = "Pl wait"
    sStartProcess = String.Format("<script language=""JavaScript"">document.getElementById("" {0}"").click();</script>", cmdLaunch.ClientID)
    RegisterStartupScript("process",sStartProcess)
End Sub

Private Sub cmdLaunch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLaunch.Click
    'Here's the code that takes a long time to process
    lbl.text="Processed successfully'
Enb Sub


Peter
------------------------------------------------------
Work smarter, not harder.