Click here to Skip to main content
15,896,730 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I've been trying things for a day and a half with no luck, so please be kind. I've been to all the websites referenced in many of the solutions about this question, but I am still stuck.

I've got a C# Web Application that (of course) puts up an aspx page. Upon a button click I want to display a modal popup of another page that contains various controls. Data must be passed to the modal window as well as from the modal window.

I've downloaded the AjaxControlToolkit and looked at the documentation, but I still can't figure out how to do this. I'm guessing it has something to do with the ModalPopupExtender, but that's just an *extender*, not a control.

I've also tried out-of-the-box Ajax (e.g., "GET", etc.), but no luck.

Can someone please provide an example of how to generate a modal popup from my web application? I can't take another day of bashing my head against the wall. (Note: I don't care how it's done -- Ajax, the AjaxControlToolkit, JavaScript, whatever. I just need to get this to work.)

Thank you.
Posted

I had to use the same thing in my website. Well, You may use a ajax model popup or colorbox Jquery for this.
I can provide you my code sample, if it helps.

1) ModelPopup Example:
XML
<form id="form1" runat="server">
    <div>
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
        <asp:Button ID="Button1" runat="server" Text="fill form" />
        <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" CancelControlID="Button2" TargetControlID="Button1" PopupControlID="Panel1">
        </asp:ModalPopupExtender>
        <asp:Panel ID="Panel1" runat="server" CssClass="Popup" align="center" style = "display:none">
        <iframe style=" width: 350px; height: 300px;" id="irm1" src="test2.aspx" runat="server"></iframe>
        <br/>
        <asp:Button ID="Button2" runat="server" Text="Close" />
        </asp:Panel>
    </div>
    </form>

this will show you test2.aspx page as popup in modelpopup.

2) using Colorbox Jquery
XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
   <link rel="stylesheet" href="http://www.formmail-maker.com/var/demo/jquery-popup-form/colorbox.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
        <script src="http://www.formmail-maker.com/var/demo/jquery-popup-form/jquery.colorbox-min.js"></script>
        <script>
            $(document).ready(function () {
                $(".iframe").colorbox({ iframe: true, fastIframe: false, width: "450px", height: "480px", transition: "fade", scrolling: false });
            });
        </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <a class='iframe' href="Default.aspx">Contact Us</a>
    </div>
    </form>
</body>
</html>

this will show you Default.aspx in pop-up.

Both codes work for me and I hope you were looking for this. If not then let me know. :)
 
Share this answer
 
Comments
dysert 22-Aug-14 8:22am    
This is very helpful, Ashi. Thank you. I just have one more question. By using a Session variable, I'm able to pass data from the main form to the popup window, but I can't figure out how to pass data from the popup window back to the main form. Any ideas?

Thanks!
dysert 22-Aug-14 10:11am    
Ok. I figured it all out. As soon as I create a simple step-by-step approach to the whole thing I'll be posting it as the answer. Stay tuned!
There are plenty of working code sample. See, in particular, this CodeProject article: ASP.NET AJAX Control Toolkit ModalPopupExtender Control in Action[^].

You cannot do programming by "luck" and make yourself depending on available code samples. You need to be able to read the documentation and use the library, or write the library by yourself. Imagine that those who created those libraries asked such questions and complained about "no luck". What could we have then?

—SA
 
Share this answer
 
v2
Comments
dysert 21-Aug-14 16:43pm    
Thanks for the reply, Sergey. I've been doing programming for over 30 years. I know how to read (and write) documentation, use a library, experiment with snippets and ideas, etc. I've pored over the article you pointed me to several times. I get an error on the very first piece of example code where it talks about using the "cc1:modalpopupextender" tag. It complains about "cc1" not being a recognized tag prefix. And it's all downhill from there.

Can you/someone please provide some much-needed help? Thanks.
Sergey Alexandrovich Kryukov 21-Aug-14 17:05pm    
Hm... well, sorry. But it looks strange to me that such a well-known control is not working... And did you try jQuery dialog or "modal popup" as well?
—SA
dysert 21-Aug-14 18:58pm    
jQuery is about the only thing I haven't tried. I guess that will be what causes tomorrow's headache unless some kind soul who knows how to do this comes to the rescue.
Sergey Alexandrovich Kryukov 21-Aug-14 19:06pm    
I tried different jQuery modal pop-ups and dialogBox, always worked without any problems, there is a lot of code sample and 3rd-party components. If depends on what you need to do with those popups. jQuery provides for extremely maintainable, well-readable and light-weight code...
—SA
prasanna.raj 22-Aug-14 0:17am    
If it possible show me your code...
How to use a modal popup window in ASP.NET and pass data between the main window and the popup window.

I’m using Visual Studio Premium 2013 and the Ajax Control Toolkit.

1. Download the Ajax Control Toolkit from https://ajaxcontroltoolkit.codeplex.com/[^], and add it to Visual Studio's Toolbox. Instructions are under the site's documentation tab.

2. In Visual Studio, go to File -> New -> Web Site

3. Choose "ASP.NET Web Forms Site"

4. In Solution Explorer, right-click the newly-created project and select Add -> Web Form. Specify "Main" for the item's name.

5. With Main.aspx up in design mode, add the ToolScriptManager control from the Ajax Control Kit toolbox items.

6. For my example, I created two textboxes and a "Popup" button on the Main page. One textbox contains the text "This is from Main". The second textbox will be filled in after the popup window is closed.

In Main.aspx, add a JavaScript "clicked" function and the various controls as shown in the source code below (which is the complete source for Main.aspx):

ASP.NET
<![CDATA[<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Main.aspx.cs" Inherits="Main" %>]]>

<![CDATA[<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>]]>



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <script type="text/javascript">
        function clicked()
        {
            location.reload();
        }
    </script>
    <form id="form1" runat="server">
    <div>
        <asp:toolkitscriptmanager id="ToolkitScriptManager1" runat="server" xmlns:asp="#unknown">
        </asp:toolkitscriptmanager>
        <asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown">This is from Main</asp:textbox><br />
        <asp:textbox id="TextBox2" runat="server" xmlns:asp="#unknown"></asp:textbox><br />
        <asp:button id="Button1" runat="server" text="Popup" xmlns:asp="#unknown" />
        <asp:modalpopupextender id="ModalPopupExtender1" runat="server" cancelcontrolid="Button2" xmlns:asp="#unknown">
            TargetControlID="Button1" PopupControlID="Panel1" OnCancelScript="clicked()"></asp:modalpopupextender>
        <asp:panel id="Panel1" runat="server" cssclass="Popup" align="center" style="display:none" xmlns:asp="#unknown">
        <iframe style=" width: 350px; height: 300px;" id="irm1" src="Popup.aspx" runat="server"></iframe>
        <br />
        <asp:button id="Button2" runat="server" text="Close" />
        </asp:panel>

    </div>
    </form>
</body>
</html>


7. In Solution Explorer, right-click the newly created project and select Add -> Web Form. Specify "Popup" for the item's name.

8. For my example, I inserted a literal string and created two textboxes on the Popup page. One textbox contains the text obtained from Main's textbox. The second textbox contains the text "Goodbye" and gets populated in Main's other textbox when the popup window is closed.

In Popup.aspx, add the various controls as shown in the source code below (which is the complete source for Popup.aspx):

ASP.NET
<![CDATA[<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Popup.aspx.cs" Inherits="Popup" %>]]>



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
            Hello!
        <br /><asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown"></asp:textbox><br />
        <asp:textbox id="TextBox2" runat="server" xmlns:asp="#unknown">Goodbye</asp:textbox>
    </div>
    </form>
</body>
</html>


9. In Solution Explorer, right-click Main.aspx and select View Code.

In the Page_Load method, enter the two lines that deal with the textboxes. The complete source for Main.aspx.cs is shown below:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Main : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["TBMain"] = TextBox1.Text;
        TextBox2.Text = (string)Session["TBpopup"];
    }
}


10. In Solution Explorer, right-click Popup.aspx and choose View Code.

In the Page_Load method, enter the two lines that deal with the textboxes. The complete source for Popup.aspx.cs is shown below:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Popup : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TextBox1.Text = (string)Session["TBMain"];
        Session["TBpopup"] = TextBox2.Text;
    }
}


11. In Solution Explorer, right-click Main.aspx and choose Set As Start Page.

12. Press CTRL+F5 to test your site.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900