Search code examples
c#ascx

Can a single ascx page use multiple codefile which are partial classes


Can we link up two partial classes to a single ascx page.

I have gone through some of the links but could not find a suitable solution for the same. Suppose for example I am having files such as

Collection.ascx.cs and Collection.Search.cs
with Collection.ascx

I am having events like button click event, could it be placed in the partial class, as doing so would make the method unavailable.
My intention is to handle button click events and the dropdown change events in the partial class.


Solution

  • Yes, In WebApplication, It is a default nature for a .aspx (web page) and .ascx (user control).

    These are by default comes with two .cs files, separating code in partial classes (filename.aspx.designer.cs and filename.aspx.cs with same partial class)

    You can also add more .cs files to extend these partial class definition.

    But in website, it will not work, for aspx or ascx.