tags:

views:

67

answers:

3

Hello there,

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
+4  A: 

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.

Chris Marisic
I have to agree that although not what you asked, Asp.Net Mvc is seriously worth looking into and understanding. I'm sensing a fair amount of disillusionment with (normal) Asp.Net from the OP, but rather than tackling it with a leap back in time, they should consider newer and better ways of acheiving the same end. At it's inception, we abandoned about 3 months of development in favour of switching to Asp.Net MVc. We've never looked back.
spender
I've been meaning to look into ASP.NET MVC for a while, however I don't think it suits this project. These asp "pages" are not actually pages. They are html yes, but they will be pulled via ajax and injected into the DOM. I've already got huge amounts of javascript/jQuery written, I really wouldn't want to start over on a different framework. @spender: yaa sorry if I come off a bit against normal ASP.Net. I've just seen a lot of heavy/slow/buggy ones, and written several myself. Just my opinion, but I find pages when I write my own JS+ajax perform a lot better / better user experience.
csauve
MVC directly matches the model you described, it's very easy to use MVC to create pages that return ragged html in the sense it has no html or body tag.
Chris Marisic
@Chris: Okay, you've convinced me :) I will take a serious look at it
csauve
+1  A: 

HttpContext.Current.Request will give you the request.

recursive
+6  A: 

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.

womp
Thanks for the note to HttpContext.Current.Request - that worked.
csauve
However, intellisense still doesn't work with the Import directive
csauve
What version of VS are you using? Also try any/all [of these settings](http://adammcraventech.wordpress.com/2009/06/23/intellisense-for-asp-net-markup-not-appearing-in-visual-studio-2008/) if you're having trouble with intellisense.
womp
@womp - that was it - needed to "open with" "web form editor". You have no idea how happy this makes me! Thanks!
csauve
No problem, glad to help. If your shop is used to classic ASP, then by all means code away in the aspx files, but when you get the time I would definitely check out the reasons for using a code file instead. There are definite advantages IMO.
womp