Button Click event not working properly

G

Guest

I have created an application that has a command button. The button is clicked and the click even contains code that looks like the following:

private void cmdCall_Click(object sender, System.EventArgs e)
{
this.lblState.Text = "Attempting Connect";

try
{
int callTest;
callTest = cell.callSite(this.txtPhone.Text);
if(callTest == 1)
{
this.lblStat.Text = "Connected";
}
else
{
this.lblStat.Text = "No Answer";
}

}
catch(Exception ex)
{
this.lblStat.Text = "Error";
this.lblError.Text = ex.ToString();
}
}

The first lblStat.Text = "Attemp Connect" does not trigger. The rest of the function works properly. But for some reason the Attempt Connect does not appear in the label that have made. This happends in other click events too. It is also a problem with one of my page load events. I use VS.Net 2003. Is there something that I need to do in order for this to work properly? I could use a timer. But I don't think I should have to do something that complex for this problem.

Thanks for your help -
Andrew
 
D

DalePres

Your code calls the label lblState at the top and then there's lblStat
further into the code. I am assuming they're the same and that one name or
the other was just typed incorrectly.

If that is the case, then the answer to your question is to add the line
Application.DoEvents(); after setting the label text to "Attempting
Connect.". That let's the system take a breather and catch up on things
like painting windows and labels, etc.

Hope that helps,

Dale

Andrew said:
I have created an application that has a command button. The button is
clicked and the click even contains code that looks like the following:
private void cmdCall_Click(object sender, System.EventArgs e)
{
this.lblState.Text = "Attempting Connect";

try
{
int callTest;
callTest = cell.callSite(this.txtPhone.Text);
if(callTest == 1)
{
this.lblStat.Text = "Connected";
}
else
{
this.lblStat.Text = "No Answer";
}

}
catch(Exception ex)
{
this.lblStat.Text = "Error";
this.lblError.Text = ex.ToString();
}
}

The first lblStat.Text = "Attemp Connect" does not trigger. The rest of
the function works properly. But for some reason the Attempt Connect does
not appear in the label that have made. This happends in other click events
too. It is also a problem with one of my page load events. I use VS.Net
2003. Is there something that I need to do in order for this to work
properly? I could use a timer. But I don't think I should have to do
something that complex for this problem.
 
G

Guest

Thanks for the reply - what if this is a ASP.net application

the DoEvents does not appear within the Application class

- Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top