Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6586245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:46:00+00:00 2026-05-25T16:46:00+00:00

I am working on an ASP.NET website which requires all server-side code to be

  • 0

I am working on an ASP.NET website which requires all server-side code to be done using the “code in front” model — I have to use server-side script blocks on .aspx, .ascx or .master pages. I would like to define a class (call it Vehicle) once within a server-side script and them import that definition on other pages or controls as needed. Is this possible?

I’d like to define this class somewhere (user control?):

<script runat="server">
  Public class Vehicle
  {
    public int Id {get; set; }
    public string Name{ get; set; }
  }
</script>

Then create an instance on site.master:

<script runat="server">
  //todo:  include the script block containing the definition of Vehicle
  public Vehicle v = new Vehicle{ Id=1, Name="Car1"};
</script>

Then use it on default.aspx:

<script runat="server">
  Response.Write (master.v.Name);
</script>

I know this works against ASP.NET but the point is that I can’t recompile the site or deploy another assembly, I can’t create .cs source files, only asp.net pages or controls.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:46:01+00:00Added an answer on May 25, 2026 at 4:46 pm

    You won’t be able to keep all of your classes inside of .as?x files, but I gather that what you want is “compile on the fly”. You can do the same thing, and still put your classes into .cs files as is appropriate, by creating an App_code directory. As stated here, code in that folder is automatically compiled at run time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an ASP.NET website which targets desktop browsers. We want to enable
I'm working on an ASP.NET website where I am using an asp:repeater with paging
I am working on ASP.Net 2.0 website and I have a strange problem. First
I'm working on a website powered by .NET asp/C# code. The clients require that
I am working on an ASP.NET website which uses forms authentication with a custom
I am working on a ASP.NET MVC website using Nhibernate as my ORM. The
I'm using ASP.NET MVC 3 code-first and I have added validation data annotations to
I'm working on a Website Project (as opposed to an ASP.NET Web Application) which
I am working on a website in asp.net mvc. I have a route routes.MapRoute(
I am working a e-commerce website (in asp.net & c#) where which I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.