C# – Converting ASP Web Form to User Control

asp.netcnetuser-controlswebforms

I have a Web Form page that is called Search.aspx. I need to render the form in other places so I'd like to convert the Web Form to a User Control, but my Search.aspx.cs inherits a custom Page class which inherits System.Web.UI.Page. Since I C# doesn't support multiple inheritance, I'm unable to inherit both my custom Page class and System.Web.UI.UserControl class in my User Control Search classs (Search.ascx.cs) class.

I was wondering if there was a way around this without having to create a second custom page class for the UserControl.

Thanks in advance.

Best Answer

What does the Search form need from the inherited custom Page class? You could design your search form so that it is nothing but a form of inputs and public properties that expose the input values. It's hard to say what the best answer is without more information about what value the custom Page class provides. Typically, controls won't need to know much about their parent page.

Related Topic