Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would an ASP.NET page be empty, but for a user control (.ascx)?

Tags:

c#

asp.net

I was hired to do some maintenance to a web site, and I found that there is a user control (.ascx) for every page (.aspx) and only one, like a one-to-one, and every .aspx is empty except for the user control. I dont see the use of that, because every user control is the entire page. Is there a benefit for doing that, or is it useless? I'm afraid to say is something useless becouse I dont have much experience.

like image 620
Samuel Avatar asked Aug 09 '12 23:08

Samuel


People also ask

What is ASCX page in asp net?

ascx file, also known as a user control, requested from a server that hosts an ASP.NET Web application. The file must be called from a Web Forms page or a parser error will occur.

What is the use of user control in asp net?

User controls are containers into which you can put markup and Web server controls. You can then treat the user control as a unit and define properties and methods for it. Custom controls. A custom control is a class that you write that derives from Control or WebControl.

What is user control in asp net c#?

A User Control is a reusable page or control with an extension of . ascx and created similar to an . aspx page but the difference is that a User Control does not render on its own, it requires an . aspx page to be rendered. User Controls are very useful to avoid repetition of code for similar requirements.

Is an extension for Usercontrol file?

The file name extension for the user control is . ascx.


2 Answers

My site is built like this: I have several .ascx files and several .aspx files that contain just one user control.

Now there's also a special .aspx file that's actually a single-page application on which I register every .ascx control. The reason I have .aspx files for both the single-page application and for each separate "page" is that during development, I'm mostly working on one "page" at a time so I don't need to load all the other modules of the application. By keeping each module in a separate .ascx file I can make changes to a module and the changes will seamlessly affect both the single-page version of the site as well as the .aspx page I use for development purposes.

Hope this helps.

like image 81
frenchie Avatar answered Sep 28 '22 21:09

frenchie


The UserControl is useful as it can be used in many places throughout the application. If its only specific to one page, the user-control loses its purpose.

User-Controls are supposed to be modular and supposed to be designed that they can easily be used in other pages.

From the sounds of the application your maintaining, you'll have to see if the user control is unique to the page, or if its the same user control is used through the app and decide to move things.

like image 23
Jason Jong Avatar answered Sep 28 '22 22:09

Jason Jong