How Do You Create a Popup Window in C#?

How do you create a popup window in C#?

Thanks,

Dan
danielolorenzAsked:
Who is Participating?
 
starlite551Connect With a Mentor Commented:
OK I have the perfect solution for you.. All you need to do is follow a few simple steps and you get windows forms Message Box Control or Form class itself accessible in the Web Application. So here are the steps :
1. Go to Solution Explorer Right Click on The Project and Click on Add References.
2. An Add Reference Dialog Box Will Appear.
3. In The .NET Components Section Browse Down Till You See System.Windows.Forms Namespace Reference.Select that by clicking the checkbox next to it and click on OK.
4. After you have done so. Go to the Code Section of your .aspx.cs Page. At the top of the code file in the namespace references using statements list add the following line :
 
using System.Windows.Forms;

Open in new window

5. Now you can call classes that reside within this namespace directly in your Web Application.
6. For Example you can then use the following code in a button click event :
protected void Button1_Click(Object sender,EventArgs e)
{
      MessageBox.Show("You Clicked "+Button1.ClientId.ToString()); 
}

Open in new window

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
WinForms or WebForms?

Can you elaborate more on what you consider a "popup" window to be and/or contain?
0
 
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
The following would display a custom windows form (called myform) as a modeless window.
myform.Show();

Is that what you wanted ?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
danielolorenzAuthor Commented:
a myform would be perfect.

How do you import?  It does not recognize it.
0
 
danielolorenzAuthor Commented:
I could also use WinForms if you show me how to use it.
0
 
danielolorenzAuthor Commented:
This is a small popup for a web application
0
 
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
OK, I'll repeat my comment with a small change

The following would display a custom windows form (called YourCustomFormNameGoesHere) as a modeless window.
YourCustomFormNameGoesHere.Show();

Is that what you wanted ?



YourCustomFormClassNameGoesHere YourCustomFormNameGoesHere = new YourCustomFormClassNameGoesHere();
YourCustomFormNameGoesHere.Show();

Open in new window

0
 
danielolorenzAuthor Commented:
Yes, this is what I want.  It is for a web application.  How do you code this from scratch?
0
 
danielolorenzAuthor Commented:
I am getting an error
0
 
BlueYonderConnect With a Mentor Commented:
Ajax may be your best option.  Download ajax from http://www.asp.net/ajaxlibrary/download.ashx.  Follow the tutorial for the modal popup.  http://www.asp.net/ajaxlibrary/act_ModalPopup.ashx.  Add <%@ Register Assembly="AjaxControlToolKit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> above all content tags, but below the page.  Add a script manager to the page, it is in the ajax tools and add it into the maincontent part of the page.  it looks like    
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablePartialRendering="true">
    </asp:ToolkitScriptManager>
0
 
danielolorenzAuthor Commented:
That was great help.  Your solutions were very good.
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.