8

I was attempting to add MessageBox.Show(Message); and it was not found in my C# .net web application (button click method and also in Page_Load).An error showing like

'The name 'MessageBox' does not exist in the current context'

Do I need to add any assembly reference for this? (I am using .net framework 4). Is there any alternative method for this?

Soner Gönül
99k103 gold badges224 silver badges375 bronze badges
asked Apr 1, 2013 at 10:44

4 Answers 4

5

The key words in your description are

web application

This functionality is only available in client (WinForms, WPF) based applications, not ASP.NET. To do this in a web app you will need to use Javascript, as illustrated in this previous Stack Overflow question.

answered Apr 1, 2013 at 10:47

Comments

3

Use This:

System.Web.UI.ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('" + Message + "')", true);

Hope This help.

answered Apr 1, 2013 at 10:58

Comments

3

System.Windows.MessageBox is used in WPF applications and System.Windows.Forms.MessageBox is used in Windows Form applications but your project is WebApplication so you don't have access to any of them.

answered Apr 1, 2013 at 10:52

2 Comments

really!!! all you need to do is add the reference of System.windows.Forms in the project and MessageBox.Show() will work. Try it in any Asp.net application. But I am not sure what will happen after deploying in IIS and then using from non MS-OS
@NewtonSheikh for more clarification you may have a look at other answers for this post.
2

The MessageBox class in the System.Windows.Forms namespace is usable from Windows Forms and Not ASP.NET Web Forms.

answered Apr 1, 2013 at 10:48

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.