Why is messagebox displayed behind the application?

I have a regular message box popping up from the server side (see code below). It works fine, but it pops up frequently behind the application at the very initial one or two poppings. I can see the messagebox icon on the bottom window bar (see attached). If I minimize the appliation, I can see the message box. See the attached. I can choose OK or Cancel on the box. It seems that it won't display behind the application again after that. If I did not minimize the application and I did not see the icon, I would not be able to respond the messagebox, and the application would be hanging up.

I'm wondering why that happens? How can I fix it?

protected void DevSelected(object sender, System.EventArgs e)
{
     ... ...
     if (MessageBox.Show("Are you sure you want to make a switch and ignore data on this page?", "Confirm Switch", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                .......
            }
            else
                ......
}
     

See-the-last-icon.doc
LVL 1
minglelinchAsked:
Who is Participating?
 
AnuTijiConnect With a Mentor Commented:
Hi

Please refer the below link for keeping the message box on top of all the applications

http://www.codeproject.com/KB/install/TopMostMessageBox.aspx
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
Since it happens only on the first showing, I suspect that DevSelected is called before the application has had time to display its form. So the form appears over the MessageBox.

Try System.Windows.Forms.Application.DoEvents ( ); just before showing the MessageBox. This instruct the application to finish processing its event queue, leaving the time for the form to display before going for the MessageBox.
0
 
minglelinchAuthor Commented:
I tried System.Windows.Forms.Application.DoEvents ( ); it happens again at the second and the third popping. After that, it works fine.

It seems happening at the second time always.

Please help. I really need it resolved. Thanks.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
minglelinchAuthor Commented:
This is how I put the statement

protected void DevSelected(object sender, System.EventArgs e)
{
     ... ...
     System.Windows.Forms.Application.DoEvents();
     if (MessageBox.Show("Are you sure you want to make a switch and ignore data on this page?", "Confirm Switch", MessageBoxButtons.YesNo) == DialogResult.Yes)
      {
         ... ...
      }
      ... ...
}
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
Is DevSelected inside of the application that displays the form, or in an external dll? The DoEvents should be in the application.

Could you post the code that calls DevSelected? This would enable us to see the event that is calling it as well as what is happening just before. A copy of the Stacktrace could also be useful.
0
 
minglelinchAuthor Commented:
Thank you so much for hte help.

Please see the attached file which contains related information.

How can I get a copy of Stacktrace ?

MessageDisplay.txt
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
Oops! ASP. Sorry, not by field.

I hope somebody can take the lead from here.
0
 
minglelinchAuthor Commented:
ASP.NET /C#
0
 
minglelinchAuthor Commented:
That's a nice answer. It eventually works. Thanks a lot.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.