Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delayed form update on button click event

Status
Not open for further replies.

dgladden

Programmer
Jul 10, 2003
2
0
0
US
I am writing an import utility that needs to display information durring the import process.

When the Import button (Button2) is clicked, the form should disable several of the input controls, and show a messages that says "Import Started". When finished importing it should say "Import Finished", and then reenable the controls.

Instead, what is happening is there are no updates to the form until the Button2_Click sub is finished. The result is that the form never says "Import Started" during the import. The form becomes unresponsive durring the import process and then shows "Import Finished" when it is finsihed.

Any idea why it is doing this?

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Enabled = False
TextBox2.Enabled = False
Button1.Enabled = False
Button2.Enabled = False
Label3.Text = "Import Started"

ImportData(TextBox1.Text, TextBox2.Text)

Label3.Text = "Import Finished"
TextBox1.Enabled = True
TextBox2.Enabled = True
Button1.Enabled = True
Button2.Enabled = True
End Sub
 
I do not think DoEvents will do it since the Click code is executing on the Server and any changes to controls in button click event on the Server will not take effect until the entire page is re-rendered to the client. A Web Page and a Windows Form are not analogous in this fashion. The "Import Started" message will have to be displayed by script already on the client page.

Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Whats probably happening is the code is excuting faster than the form can update so it appreas that the label does it change. Visually it hasn't but progrmatically it has.

Try a refresh on the label prior to the import like the following.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Enabled = False
TextBox2.Enabled = False
Button1.Enabled = False
Button2.Enabled = False
Label3.Text = "Import Started"
Label3.Refresh()

ImportData(TextBox1.Text, TextBox2.Text)

Label3.Text = "Import Finished"

TextBox1.Enabled = True
TextBox2.Enabled = True
Button1.Enabled = True
Button2.Enabled = True
End Sub


"Shoot Me! Shoot Me NOW!!!"
- Daffy Duck
 
I've eliminated the possibility of it going to fast to see... I put a pause in the ImportData sub, so that should allow me to see the update. I also tried stepping through the lines of code and watched it's behavior.

Anyway... It magically stopped doing it... not sure why. Basically I got tired to fighting with it and just finished the functionality of the program and when I did final testing it started to work correctly.

Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top