4

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
1
  • You should look into ASP.NET DataBinding. It'll reduce a lot of dependency on code behind to begin with. However: You're going to have issues with control blocks. Commented Sep 10, 2010 at 0:08

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the note to HttpContext.Current.Request - that worked.
However, intellisense still doesn't work with the Import directive
What version of VS are you using? Also try any/all of these settings if you're having trouble with intellisense.
that was it - needed to "open with" "web form editor". You have no idea how happy this makes me! Thanks!
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.
5

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.

6 Comments

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.
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.
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: Okay, you've convinced me :) I will take a serious look at it
much easier to accomplish what he needs without MVC. MVC is a cool setup for larger projects, and if you're willing to invest the time and effort to learn/utilize a new framework.
|
2

HttpContext.Current.Request will give you the request.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.