views:

33

answers:

2

I'm pretty sure the answer is going to be no here, but I just want to be sure. As you can probably guess I'm in progress of converting a web forms project over to ASP.NET MVC. Thus, I have a web forms master page and a MVC master page. The user controls (.ascx) render fine in the MVC Master page, but the post-backs essentially do nothing.

The best solution I know of is to have partials instead of user controls for the MVC master page. And then have an abstract controller that any controller that uses the MVC master page inherits from. Not exactly DRY, but it's the only thing I know of at this point. Any better ideas?

Thanks! Darren

A: 

You're correct - postback from a user control just won't work in a Mvc environment.

What I have done in a similar project is to gradually migrate the UserControls over to Partials called from MVC or from within webforms. [shameless plug] I have written about how to call RenderPartial and RenderAction here: http://www.blog.clicktricity.com [/shameless plug]

Clicktricity
Cool, I used RenderAction and partials to get the job done. Thanks for the link. That'll get rid of my current code duplication between the web forms controls and the MVC partials.
Darren
A: 

Hey,

Controls to postback such as submit buttons would work fine; anything that renders __doPostBack would not work, such as <button>, <a> (or LinkButton), <input type="button" />, etc.

Also, not sure of all the context, but consider the Html.Action MVC 2 syntax (if using MVC 2) as a way to achieve it too, which may be better depending on what's going on within the control.

Brian
Thanks Brian. I went the HTML.Action route which actually pointed to a partial and that worked well.
Darren