Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net without codebehind

Tags:

c#

asp.net

I would like to create an ASP.Net page without all the codebehind and designer stuff. Basically I want to go back to ASP classic, but keep the CLR and Base Class Library that makes .Net oh-so-wonderful. I'd like just a page something like this:


<html>
<body>
<div>

  <%
    int customerID = Request.QueryString["CustomerID"];
    //Customer and DataAccess classes come from an extenal assembly
    Customer customer = DataAccess.GetCustomer(customerID); 
  %>
  You asked for Customer with ID: <%=customerID;%><br />
  Name: <%=customer.Name;%><br />
  Phone: <%=customer.Phone;%><br />


</div>
</body>
</html>

However there seem to be some problems with that.

  • The Request object is only available from within a Page object. I wish to completely delete the codebehind and designer pages.
  • No intellisense
  • Anything else I should be aware of before I get too deep into this?
  • No idea how to start pulling in extenal libraries
like image 839
csauve Avatar asked Dec 07 '22 01:12

csauve


2 Answers

You don't need to do anything in code-behind if you don't want to.

To import namespaces, use an import directive:

<%@ Import namespace="System.Web" %>

To import external libraries, use an Assembly directive:

<%@ Assembly Name="YourAssemblyName" %>

Importing System.Web will allow you intellisense access to the HttpContext.Current.Request object. It will also give you intellisense for any other objects in that namespace, just like a code file.

like image 69
womp Avatar answered Dec 28 '22 17:12

womp


I think your best bet is to look at ASP.NET MVC, specifically with the Razor View Engine.

You will still have some tooling around this though.

like image 42
Chris Marisic Avatar answered Dec 28 '22 17:12

Chris Marisic