Hi, I need to open a ascx control as a popup window (so that I can then allow a button to do a window.print() inside it) How do I pass the Html result of the ascx control into a popup window? Possibly using javascript? I want to keep it with the MVC way of
doing things ideally Thanks!
Could I be trivial and ask for the exact parameters to pass to the window.open call? Right now I am rendering the ascx control partially within my form using RenderPartial("controlName", ViewData.Model) so that it displays it in my main page but how can I pass
the model and .ascx control into a window.open? Also..to keep it in the MVC way of doing things, should this window.open be in the aspx code or code behind?
Not really pretty, I know. but the alternative is setting up a function and putting this url info into a global js variable. since this was dmeo code, I've just put here the quickest solution I've found.
--
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu
Hi Luis, Thanks for your help, I have got this far but the problem is it just comes up with a 404 error as the control is an ascx control (currently rendered partially by passing in the ViewData object and the control into a System.Web.Mvc.Html.RenderPartial
object). The thing is the window popup opens the control, but because it has no ViewData passed into it, it falls over, if that makes sense? Is there a way around this? If not is there a way to obtain the Html Result of the ascx (after its parsed/rendered)
and pass this html directly into the window.open? Thanks again for your time
hum...I'm not following...if it currently is rendered through RenderPartial method then you need to change your code so that you have a controller method that returns that partial view. Even better, why don't you add a view wich only renders that partial
view and then add a method to your controller which returns that new view? I believe that would be a good option for this scenario because the partial view won't render a complete HTML page...
--
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu
Your popup window needs to be a complete HTML document, so you shouldn't be using a user control for this. You won't use your master page of course, but just a plain MVC View Page. You'll need a controller & action to point to this. Let's say you have a link
that you want to popup a window to show your privacy policy... The link: The script to wire up the popup behavior (jquery): $("a.popup").click( function(link) { window.open(a.href, "", "width=400; height=500; toolbar=no; menubar=no"); return false; }); and
the controller: public class HomeController : Controller { ...more actions public ActionResult Privacy() { return View(); } } then create a regular aspx view (no master page) that contains the privacy policy. By doing it this way your users that have javascript
disabled will still make it to the content, it just won't happen in a popup. If you have javascript, you get the better functionality.
Hi Guys, Thanks again for all your help, I think I haven't been very clear in what I need. I understand the bit about using javascript to make another popup and putting the ascx control in another MVC View Page (which will be the popup). But the problem is
my ViewData.Model object, has data contained in it which is needed by the control and the page it currently sits in. Currently I have a aspx MVC page, which the control sits in (partially rendered in using RenderPartial("controlName", ViewData.Model)) this
way, the ascx control can access all the ViewData.Model object/data. However if i create a separate popup how can I pass the same ViewData.Model object/data into it? In the same way I did with the RenderPartial method? Without it being cleared out? Does you
see my problem? Thanks!
hum...whatt kind of data are we talking about? data that exists on the page that is currentyl displayed to the user? data that exists in the server? if it's on the page displayed to the user then you could send it back to the server and rebuild the object
there before passing it to the partial view...probably through the query string, if it isnt' sensitive information or if it's not too big...
--
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu
sparklem
0 Points
5 Posts
Open a ascx control popup window the MVC way?
Feb 02, 2009 01:13 PM|LINK
Luis Abreu
All-Star
25674 Points
5369 Posts
MVP
Re: Open a ascx control popup window the MVC way?
Feb 02, 2009 01:44 PM|LINK
Hello,
anything wrong with calling window.open and passing an url which points to your controller/action url?
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu
sparklem
0 Points
5 Posts
Re: Open a ascx control popup window the MVC way?
Feb 02, 2009 01:52 PM|LINK
Luis Abreu
All-Star
25674 Points
5369 Posts
MVP
Re: Open a ascx control popup window the MVC way?
Feb 02, 2009 02:23 PM|LINK
Here's a quick example:
<input type="button" value="bt" onclick="window.open( '<%= Url.Action( "About", "Home" ) %>' );"
Not really pretty, I know. but the alternative is setting up a function and putting this url info into a global js variable. since this was dmeo code, I've just put here the quickest solution I've found.
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu
sparklem
0 Points
5 Posts
Re: Open a ascx control popup window the MVC way?
Feb 02, 2009 02:32 PM|LINK
Luis Abreu
All-Star
25674 Points
5369 Posts
MVP
Re: Open a ascx control popup window the MVC way?
Feb 02, 2009 05:29 PM|LINK
Hello again.
hum...I'm not following...if it currently is rendered through RenderPartial method then you need to change your code so that you have a controller method that returns that partial view. Even better, why don't you add a view wich only renders that partial view and then add a method to your controller which returns that new view? I believe that would be a good option for this scenario because the partial view won't render a complete HTML page...
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu
subdigital
Contributor
2105 Points
445 Posts
ASPInsiders
Re: Open a ascx control popup window the MVC way?
Feb 02, 2009 05:59 PM|LINK
http://www.flux88.com
ASP.NET MVP
Certified ScrumMaster
ASPInsider
MCSD
Luis Abreu
All-Star
25674 Points
5369 Posts
MVP
Re: Open a ascx control popup window the MVC way?
Feb 02, 2009 06:10 PM|LINK
Yep, that will do it, though the a.href will only work if you're using an anchor...
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu
sparklem
0 Points
5 Posts
Re: Open a ascx control popup window the MVC way?
Feb 03, 2009 09:35 AM|LINK
Luis Abreu
All-Star
25674 Points
5369 Posts
MVP
Re: Open a ascx control popup window the MVC way?
Feb 03, 2009 09:48 AM|LINK
hum...whatt kind of data are we talking about? data that exists on the page that is currentyl displayed to the user? data that exists in the server? if it's on the page displayed to the user then you could send it back to the server and rebuild the object there before passing it to the partial view...probably through the query string, if it isnt' sensitive information or if it's not too big...
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu