Partial Class for ASPX pages

A

Aryan

Hi,
I have problem in creating Partial Class for ASPX pages.
As my Codebase file for ASPX page is having more then 2500 lines of
code. So its very hard to maintain the code. So I wanted to know, how
can I create partial classes to handle this situation OR if I create
new class files in App_Code folder to handle major code of ASPX code
behind page then how can I get the access to the various Web Control
which I have created on the ASPX page???



Please suggest me a way to handle this situation.

Thanks & Regards,
Manoj Singh
 
C

Cowboy \(Gregory A. Beamer\)

If you have gone beyond maintainability in your ASPX pages, it is time to
move to libraries. While partial classes might be tempting, it is not a wise
direction to improve maintainability.

The first step is to use App_Code and create the classes. Ultimately, you
will want to group like classes and create external libraries. During the
heaviest development cycle, it may not be wise to take this step, but it is
imperative for reusability of code across multiple applications.

Overall, the ASPX page should be a thin veneer over the working code. If you
find more than a few dozen lines of code in a page, your UI is probably
doing too much business rules type of work and needs refactoring.

Here is a good step by step plan
1. Move all repetitive code into functions
2. If you find repeate of functions across pages, move them to a class in
App_Code
3. Once you have all code refactored to class, determine which classes (or
functions) should reside in the same library and move them to an external
project (you can use project references to start).
 
S

Steve B.

How can you reach 2500 lines of code in a aspx page ?
I'm developping aspx page for 5 years and I never rich a so huge page.

I presume all of your business process is code directly in the pages.
Try to isolate your processes in as many classes as you need, and even in
separated assemblies.

You will gain not only readability but also scalling and maintenability of
your code.

Steve
 
A

Aryan

Thanks for your help, what I am doing is binding my various ASP.NET
controls to the respective datasource. In code behind file I am binding
control as given below..Since I am having various ASP.NET controls in
my ASPX page and their properties are getting set in CodeBehind file
and because of this the page size is getting larger and larger.. So I
just wanted to know, if I create seperate Class files to handle these
property settings then how can I access the ASP.NET controls in those
seperate Class files.

As in given below example if I have dropdown control called
(ddCTROrganization) in ASPX page then how can I access this
(ddCTROrganization) control in any other Class files.

For examle.
If Not IsNothing(dvOrgList) Then
ddCTROrganization.Items.Clear()
ddCTROrganization.DataSource = dvOrgList
ddCTROrganization.DataTextField = "OrgName"
ddCTROrganization.DataValueField = "iIDOrganization"
ddCTROrganization.DataBind()
Else
............
..........
End if

Thanks Again.
Manoj Singh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,701
Latest member
XavierQ83

Latest Threads

Top