Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
I've been struggling with what seemed like an easy task in for longer than I would like. I thought this would be easy, since I understand the syntax of C/C++, JavaScript, VBScript, and VB.Net.
I have an aspx page and I would like to include a c# source file that defines and calls a function that uses HTTP Response. I do not want to have any of this code on the aspx page because there is no syntax coloring for c# embedded on an aspx page in Notepad++.
Any help would be appreciated. Here's some pseudo code to help you understand where I'm trying to end up:
<%@ Page language="c#" Src="test.cs" %>
using System.Web.HttpContext.Current.Response;
public class myclass()
    public void myfunction()
        Response.Write("Hello World");
Also, do you -have- create an object from a class before accessing the members of it? C++ allows direct access to a classes' functions via the :: operator.
Posted 9-Aug-12 7:07am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

<![CDATA[<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<html xmlns="">
<head  runat="server">
    <form id="form1"  runat="server">   
Your csharp code will be:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
    public partial class WebForm1 : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
Remember that .NET uses OOP paradigm =)
May be this helps you:[^]
Hope you find it useful.
Xaltus at 16-Aug-12 11:15am
Hi. Thanks for your reply. Just a quick note:
This did not work and came back with an error:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

It says it couldn't inherit WebApplication1.WebForm1
However, this does work:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Src="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

Also, it said that System.Linq is not a valid namespace, so I removed it. This works like a charm. Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 420
1 OriginalGriff 344
2 Peter Leow 200
3 John C Rayan 126
4 CHill60 90
0 Sergey Alexandrovich Kryukov 7,393
1 OriginalGriff 5,711
2 Peter Leow 4,157
3 CHill60 2,858
4 Mika Wendelius 2,850

Advertise | Privacy | Mobile
Web02 | 2.8.150224.1 | Last Updated 9 Aug 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100