Some time ago I tweeted [ Follow Me ] that you could write ASP.NET applications without using Web Forms or ASP.NET MVC
Frameworks are a convenience ! Web Forms, MVC, Cake, Symphony, etc.
So what if you want to use the power of the .NET framework, but want complete control over the client code and don’t want to be forced to use the MVC pattern.
No Problem – ASP.NET and Web Forms are not synonymous !!
Look at these 2 “Hello World” applications.
PHP Hello World
1: <html xmlns="http://www.w3.org/1999/xhtml">
2: <head>
3: <title></title>
4: </head>
5: <body>
6: <?php
7: echo ("This is a test !");
8: ?>
9: </body>
10: </html>
ASP.NET Hello World.
1: <%@ Page Language="C#" %>
2: <html xmlns="http://www.w3.org/1999/xhtml">
3: <head runat="server">
4: <title></title>
5: </head>
6: <body>
7: <% Response.Write("This is a test !"); %>
8: </body>
9: </html>
On the ASP.NET side, I could include YUI or jQuery and still use ASP.NET controls if I wanted or not use any server side controls and even turn off view-state.
If you don’t have call response.write you can even use the short hand …
<%= "This is a test !" %>
I can still code to the page lifecycle events if I want, or, code for top-to-bottom execution as seen above !
Form and Query String Variables are all accessible via the request object (and tons of other stuff)
Give it a try !





















Thats what we call classic ASP:)
To the contrary Osman. It’s still .NET and that is the point.
Well actually you can do the same thing with code behind too :
.aspx.cs file :
protected string HelloMessage { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
HelloMessage = string.IsNullOrEmpty(Request["btnSubmit"]) ? "Hello World !" : "Hello Again World !!";
}
.aspx file :
<body>
<form action="testtemp.aspx" method="post">
<div>
<%= HelloMessage %>
<input type="submit" name="btnSubmit" value="Say again ?" />
</div>
</form>
</body>
Now you have the best of the two world \o/
I’m even sure there’s a way to use the controls without having the ViewState (like calling their render method and writing that in the stream), but that’s beside the point you were trying to make I guess
Ahhh I get your point.
Ugh, why not just use the MVC pattern. Its cleaner, neater and you can actually test it. How would you test your Hello world example?
John, you’re missing the point. The point is not to say "everone should do it this way", the point is that different develoeprs and different projects are well fitted by different approaches and ASP.NET offers the flexability to choose the one that best fits.
Good article.
When working on the .NET 1.1 Framework, I mandated that every developer working in the programming team completely eschew all ASP .NET controls ( and ViewState ) with four exceptions – UserControls, Repeater, PlaceHolder and in very rare circumstances – the Literal.
There were a ton of good reasons for doing so. For starters, we were producing public facing websites. .NET 1.1 was not great at producing the exact markup we needed, even with a large browserCaps section.
At the time, our designers were using CSS selectors based on the ID of an element. The client-side auto-naming was not helping us here. Plus, the use of .NET controls meant that
We also wanted to keep page weight nice and low, which meant getting rid of viewstate. You might be amazed to know that we also dismissed all of the built-in Validators.
Certain things were not great ( e.g. ternary operators on forms ) but overall, everybody benefited from the experience.
Developers got to know a lot more about actual XHTML, most learned Javascript, the sites we developed after instituting the policy were significantly more performant and relationships between programming and design depts hit an all-time high.
Even now, I’d still consider taking the same approach on a public site.
The .NET Framework has been a revelation, and I couldn’t be without it. However, part of the craft of using it is picking and choosing what works for you and your organization.
Web pages essentially boil down to two things – GETs and POSTs. For all the layers of abstraction you might stack on top, that’s what you’re working with. I’m glad .NET was able to give me robust server side functionality without hampering my need for absolute control on the front end.
Ahh, reminds me of my old days in PHP. 8^D
As a sidenote, do you know if coding in this manner still generates the ViewState that you get with a typcial WebForms type model, or is this a clever way to avoid that for really simple pages?
Sean, there is still "some" view state, but why not just turn all view state off if not useing server controls ??
One question – how do you define webforms? To me, the ASP.NET code you posted IS still webforms. Yeah, you’ve kinda eliminated the page-controller model since you don’t have code-behind but you’ve still got controller code in-line with the aspx. If it’s mapped to the System.Web.UI.PagehandlerFactory assembly (which it is) – you’re still using webforms. If, on the other hand, you’re implementing your own handler, or perhaps even putting a module in between and handling the rendering yourself – then you’re not using webforms. Am I off-base here?
There is no use of Server Form processing or server conrols.
One would be free to implement their application using pure HTTP / HTLM / JavaScript
RE: Write ASP.NET without Web Forms or MVC !
Pingback from Write ASP.NET without Web Forms or MVC ! | I love .NET!
Yaddamaster – to me, a web form is an aspx page with a form tag with the runat="server" attribute set.
I know this differs from what VS tells you when creating the page, but I’d agree with Joe on this point.
Personally, I’d still use code-behind for all of my on-load functionality, reserving in-line to "tie-interceptor" string payloads :-
<%= SomePropertyIDefinedEarlier %>
I think this is a good point to bring up because a lot of asp.net developers don’t even think about this.
I’ve always liked keeping things as simple as possible. As long as the code is easy to understand why use 10 files where 1 will do just fine. To me the concept of having an aspx, .cs, another .cs for business logic, another .cs for helpers, another .cs for data, another .cs for something else doesn’t make sense when all you want to do is "hello world".
The only thing I’d add about using <% %> on aspx pages… in 1.0, 1.1 didn’t using those on the page mean that your page became interpreted and not compiled? It’d have to be compiled every load and that would affect performance so I never used it. At least this is what I thought then. I think in 2.0 that has changed and now everything is compiled… so now I have no problems using this other than having easier ways to do things.
RE: Write ASP.NET without Web Forms or MVC !
DotNetBurner – burning hot .net content
code-behind
@Bishop:
That’s the way I prefer.
I don’t think Reponse.Write is a good method to output a string, right?
Joe, AWESOME article … as a switch hitter on code myself (PHP/VB.NET/C#), it’s great to know that I could always switch back to this "basics" kind of programming scheme … very cool.
[as an aside everyone, it was Joe at an event in Nashua FIVE years ago who convinced me to try .NET (I only did PHP back then at PBS in Boston) ... now ASP.NET is my full time job]
Well it was interesting to know how much you can strip asp.net back to the bones but that "Give it a try!" at the end is just going to cause arguments in these comments… oh wait they already started
What benifits will getting such a control on the code give us?, when we have to start doing all the things from scratch.
If you’re not going to use ASP.NET features then why not just use a *.htm file and use JavaScript, I don’t really get this post
Dave,
The point is that ASP.NET is WAY more than just the UI bits ofthe framework.
You could use just .htm and JavaScript but you would still need to implement server side logic !
@Joe Stagner
I see you’ve already been stormed by people saying "what? why this article?" .. I even stumbled over it and left wondering… "why did he write this?" — I even sent it to a friend and asked him if he could see something that I was missing…
Alas he couldn’t find something, except, YES, it is infact possible to NOT use server-controls and code-behind in ASP.NET.
This is probably something more novice developers can use for something, and aren’t able to decypher themselves.
But, for us more seasoned developers, could you please label these types of posts with something like "Beginner" — I think more time has been wasted by seasoned developers, than has been gained by novice developers, by leaving out that VERY useful tidbit of information in the header
Am I wrong here?
Hello Misfit geek
how to i became a successful web Developer
how to be bacame a successful web developer
What the man is trying to say is that you can still have the benefits of .NET, but you can control client side code exactly as you want, as i also prefer, Joe correct me if I’m wrong. And this is not some "beginner" stuff.
webuser – you are exactly right, but you knopw, sometimes I just need to bite down and smile
You know, this is really the sort of thing I think experienced developers need to remember. I cringed when I saw "Hello World" done as an MVC application. It’s like bringing in a 20-ton rock crusher to drive a thumbtack into a cork board. Too many apps get over-coded and over-frameworked, IMHO. KISS is the rule.
In my opinion, inline ASP.NET is a great alternative for simple pages that do not need to be an integrated part of a full application. Web forms (with Agile) is the best for a 1-2 developer small to mid-size application. MVC (with full RUP) is best for a huge application with a lot of developers. There’s a time and a place for each method.
@anirdha – I’m seeing you on lots of blogs today. Here is my advice:
1) Read, read, read, then read some more
2) Read to understand, not to simply turn pages
3) Practice what you read
4) Also read non-technical books to improve your understanding of the culture and language you are trying to communicate with.
5) Learn to communicate better every day. I would not come to your native country and attempt to have conversations with you in your native language about advanced topics until I had improved my ability to use that language to the best it could be. This is crucial to effective communication, and removes the frustration that poor communication can cause. (In this case, keep learning to speak and write English better. It’s my native language and even I have to remind myself of some rules from time to time.)
These things will start you on the path to becoming a successful developer.
RE: Write ASP.NET without Web Forms or MVC !
Pingback from Write ASP.NET without Web Forms or MVC ! : Misfit Geek
Hey Bill
I did the top-to-bottom as well. I made a TwitterClient
http://bit.ly/3wgSaO
> So what if you want to use the power
> of the .NET framework, but want complete
> control over the client code and don’t
> want to be forced to use the MVC pattern.
That is not "complete control over the client code" in my opinion. Still you are sending a form to a client. At max you can communicate data without resending the form.
"Complete control over the client code" would mean that you can communicate logic, not only data asynchronously. That is, for instance, within the same form you could send a client a JavaScript code "On-Demand".
Good idea, I’ll try to blog on it in details with the code in a week or so.
I had only used ASP.NET for a couple months before I had similar sentiments. Web controls and MVC are both unnecessary complications. Give me Response.Write, Request.QueryString, Request.Form, and a good generic programming framework like C#/.NET; and I’ll handle the rest, thank you.
I felt so strongly that I put up an example page at
agalltyr.com/…/rawaspdotnet.ht
a little while ago. It’s funny someone else was thinking the same thing.
Anyone that doesn’t "get this" imo is not a seasoned WEB developer. HTML markup and JS is web programming and being able to cleanly separate this skillset from asp.net is a worthwhile function. There is a LOT to be said for semantic html, progressive enhancement and creating efficient, usable and accessible web pages that often asp.net controls will get in the way of. Ask the rest of the web.
That said, we do use web controls and I’m okay with that but that is a very specific skillset and will not be of any benefit in anything but a .net environment.