build custom control common for both ASP.NET web application and Web form application
I have to create a cu开发者_JS百科stom control that just renders scripts like object tag and some javascript file path ... and this control is going to use by both MVC and asp.net webform application
please advice if this is possible.
Your biggest challenge is how to write the HTML to the screen. MVC's controls inherit from System.Web.Mvc.ViewUserControl while WebForms inherits from System.Web.UI.UserControl so you'll have to have another class shared between your actual .ascx files.
Writing the control with beestings <% %> mixed with HTML markup is going to be complicated because of this inheritance mismatch.
Your best bet is to manipulate a string in your shared classes to get the HTML you want and then override the ToString() method with the final result. That way you can call Response.Write( lControlClassThatDoesTheWork.ToString() ) in the PageLoad ( or whatever you need ) event in your WebForms control. For MVC just create a HtmlHelper that returns an instance of ControlClassThatDoesTheWorkand the <%= %> beesting will call the ToString() method for you.
精彩评论