Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Moving my code behind to a class file

Avatar of QPR
QPRFlag for New Zealand asked on
.NET ProgrammingASP.NET
11 Comments1 Solution239 ViewsLast Modified:
I have a few pages that build an identical menu to show on the page.
It occured to me that my code behind pages were repating the same code and that I should move the block into my class file and call it from there.
It works by gathering some data and then putting it in the InnerHTML of some named <span> areas.
The data returned and the span IDs are identical acroos all pages.

My problem is that once the code is moved from behind the pages spanName.InnerHTML is no longer recognised.
How can I say that the span I'm referring to is in the page that called this method?

Part 2: This menu is static 95% of the time. Is there a way I could cache this data and then have the menu built from this on subsequent pages rather than keep going back to the server (data comes from sharepoint via web services).

Code in code window
/* This is the code that I moved from the .aspx.cs to the .cs file */

public string BuildMenu(object sender, System.EventArgs e)
string MenuTitles = "";
StringBuilder sb = new StringBuilder(MenuTitles);

string theTopics = "";
theTopics = MakeMenu("Topics", CAML query removed for readability);
TopicMenu.InnerHtml = sb.ToString();

string theIssues = "";
theIssues = MakeMenu("Issues",  CAML query removed for readability);
IssueMenu.InnerHtml = sb.ToString();

string theObjs = "";
theObjs = MakeMenu("Objectives",  CAML query removed for readability);
ObjectivesMenu.InnerHtml = sb.ToString();

string theZones = "";
theZones = MakeMenu("Zones",  CAML query removed for readability);
ZonesMenu.InnerHtml = sb.ToString();
sb = null;

/* This is how the code is called from within the aspx.cs file on page load */

ExtractListData etl = new ExtractListData();
Avatar of Vikram Singh Saini
Vikram Singh SainiFlag of India imageWeb Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 11 Comments.
See Answers