0

Hiii Alll

I need to display a message to the user after clicking the button control. How to do this in c#.net? I could not find Msgbox() option as we hav in vb.net.

can any one help me

6
Contributors
17
Replies
22
Views
8 Years
Discussion Span
Last Post by walflo
0

Hi.
If I do so Am gettin this error
Error The name 'MessageBox' does not exist in the current context
Do we hav to create a separate function or to use any namespace for this.

0

I guess the Call is done within a Form?
The MessageBox is included in the namespace System.Windows.Forms
Do you have this in your using at the top?
Or have you tried to write

System.Windows.Forms.MessageBox.Show("This is a message");
0

MessageBox is only available in Window Applicaitons. In ASP.NET, you cannot use the MessageBox class or MsgBox function like you can in a Window Applicaitons, but you can emulate this functionality by streaming out a javascript alert instruction like this:

Response.Write(@"<script language='javascript'>alert('This is my Message')</script>");
0

In ASP.NET with code Behind VB I have used msgbox().
It worked well.
But in C# :( am gettin into trouble

0

Okai..
This is my sample code for Palindrome checking.
Got a string in textbox 1.

TextBox2.Text = StrReverse(TextBox1.Text)
            If TextBox1.Text = TextBox2.Text Then
                MsgBox("String is palindrome", MsgBoxStyle.OkOnly)
            Else
                MsgBox("Not a palindrome", MsgBoxStyle.OkOnly)
            End If

This code is done in Asp.Net webapplication with VB code behind.
Can u say how to use message box with C# code behind:?:

0

So this is a Web application in c#.net
Well then you cannot use the Messagebox. This function / method
is used within an windows application
As mention earlier , you can solve this by using Javascript or ms.Ajax (Popup /modalpopup)

0

Hmmm Fine....
In C# we have to use script for messageBox.Okay let me do.
Tnx...

0

Select the function name "MsgBox", right click and from the menu select Go to Defenition and post the fuction defenition here. I suppose its a user defined function

0

Hi again

I yust wonder who this could be done..
Do as i told over.. in button click method

System.Windows.Forms.MessageBox.Show("This is a message");

then select: project -> add reference
Then scroll down to System.Windows.Forms and select this.
Press ok

0

Hi,

I dont think what Frank is saying will work when deployed (But i will gladly be proven wrong as i would like to be able to use the messagebox functionality in an asp.net app). The messagebox will throw an exception because you can not show a modal form on a clients machine when it is created server side. The only real option avaliable is to Use javascript or Ajax as someone has mentioned earlier in this thread.

0

Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "SCRIPT", string.Format("alert('Hello World')"), true);

0

This is the only solution that works within this post:
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "SCRIPT", string.Format("alert('Hello World')"), true);

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.