Thursday, April 30, 2009

The Four Pillars of ASP.NET, Web Forms, AJAX, MVC and Dynamic Data.

Source

3. ASP.NET MVC. This pillar is the newest to emerge from Microsoft. In fact, as of this writing, it’s only a couple of weeks old, having been released at Mix09. Some ASP.NET curmudgeons would call this a throwback to the days of ASP “classic” spaghetti code, but for many others--especially the alt.net crowd and transplants from Ruby and Java--this represents the cat’s pajamas on the Microsoft web stack. (Of course, it’s amazing how quickly developers find problems in the latest programmer’s paradise--usually before its release--and I’m sure the MVC aficionados are already looking to the next release.)

The basic idea behind ASP.NET MVC is to separate out the three concerns of the MVC pattern: the model, view, and controller. The model represents the data model, the view is the user interface that presents the data and interacts with the user, and the controller is the command center that takes inputs from the view, pushes and pulls data into/from the model, and decides what to do next. By separating out these concerns (as purely as possible), you improve the ability to create unit tests for your applications and, at least on some level, improve application maintainability. If you are into test driven development, then this is the pillar to hook your horse to.

Wednesday, April 29, 2009

Flexigrid link

http://code.google.com/p/flexigrid/

Lightweight but rich data grid with resizable columns and a scrolling data to match the headers, plus an ability to connect to an xml based data source using Ajax to load the content.

Monday, April 27, 2009

Is ASP.NET MVC a half-baked solution?

Source

Let's be clear, ASP.NET MVC is an improvement over WebForms - and those developers refusing to leverage ASP.NET MVC (or something else) for new projects are simply lazy. WebForms is full of leaky abstraction, really tight coupling, and ridiculous concepts - such as viewstates and postbacks.

Being able to write complex systems more cleanly is a good start, but given where web development stands in general, and other platforms specifically, ASP.NET MVC lags far behind (Perl being the only one I can think of which is worse).

There's little question that a big part of the problem is that this is really a VC stack - there is no thought, no support, and no tools for the Model. When you compare the thousands of lines you'll end up writing for your repository/dal/linq/nhiberate to other MVC stacks (which commonly only require that your models to inherit from 1 class), you're already at a serious productivity disadvantage. But the true impact is actually much worse - you lose any cohesiveness of purpose through the controller and views. There is no way to generate HTML labels from model properties, or client side validation. In frameworks such as Akelos, RoR or Django everything flows outwards from the model which allows those frameworks to provide cohesive and integrated tools, not just HtmlHelpers, ActionResults and Routing (which is all you get from ASP.NET MVC).

You end up having to do a whole lot of plumbing on both sides of your system.

Friday, April 24, 2009

How we do MVC

Source

Like many of the frameworks coming out of Redmond, MVC is not an opinionated framework. Rather, it is a framework that enables you to form your own opinions (good or bad). It’s taken quite a long way, with a very stable result at the end. It’s certainly not perfect, and there are a few directions we’d like to go differently given the chance. In the next few posts, I’ll elaborate with real examples on the big examples here, otherwise, I’d love to have people poke holes in our approach

Thursday, April 23, 2009

You Should Learn MVC (with 3 reasons)

Source

1 – Testability. No – not talking about the TDD variety, just testing in general. If you’re “not a testing person” that’s OK – the rest of the computer science world has embraced the idea that “testing what we build is a pretty good idea”. You don’t really want your clients to catch that silly “InvalidCastException” do ya? There’s LOTS of reasons to want to test – again not TDD – just good old Unit Testing! It’s easy peasy with MVC and this alone should pull you in to at least check it out – along with why testing can save you time and money.

2 – Control over HTML. I’m sure you’ve heard this before – mangled ID’s, non-validating HTML, etc. Why is this important? Because you might want to use client-side programming for something! I won’t bang this gong for too long – but it’s a lot more than “making ViewSource look pretty” – you’re communicating with super-finicky creatures (browsers) that love to argue – being able to smith the markup experience makes you a more valuable developer!

3 – Extensibility. Literally every part of MVC Is pluggable – and in the last 3 apps I wrote (Storefront, Nerddinner, and SubSonic’s MVC Starter) I used my own ViewEngine to save some time and work. I’ve spun up my own ControllerFactory so I can use IoC (which is awesome fun!) Understanding this is the keys to the kingdom for any developer! Have you ever been freaked out because you needed to use Page_PreRender to get something to load into the ControlTree properly so it will show when you need it to? MVC does not lock you into anything – you’re free to do what you want to.

Wednesday, April 22, 2009

Basic Selectors in JQuery

1. By the ID attribute.
If the ID contains special character then you can escape them with backslashes. For example to find a text box with ID txtName you can write the following :

$("#txtName")

Then you can do any operation on the text box like getting the value or changing the css class.

2. By given element name. For example to get all the DIV elements following is the syntax

$("div")

This will find all the DIVs present in the page. You can do any operation after that.


3. By given class name. The following code finds all the elements which have class name 'RedButton'.

$(".RedButton")

Source

jQuery Auto-Complete Text Box with ASP.NET MVC

Great example:
Source

"HTTP Error 500 - Internal server error" mean: you have to fix something in your code

500 errors in the HTTP cycle

Any client (e.g. your Web browser or our CheckUpDown robot) goes through the following cycle when it communicates with your Web server:

Obtain an IP address from the IP name of your site (your site URL without the leading 'http://'). This lookup (conversion of IP name to IP address) is provided by domain name servers (DNSs).
Open an IP socket connection to that IP address.
Write an HTTP data stream through that socket.
Receive an HTTP data stream back from your Web server in response. This data stream contains status codes whose values are determined by the HTTP protocol. Parse this data stream for status codes and other useful information.
This error occurs in the final step above when the client receives an HTTP status code that it recognises as '500'.

Fixing 500 errors - general

This error can only be resolved by fixes to the Web server software. It is not a client-side problem. It is up to the operators of your Web server site to locate and analyse the logs which should give further information about the error.

Tuesday, April 21, 2009

http://blog.objectmentor.com/articles/2009/04/20/is-the-supremacy-of-object-oriented-programming-over

Source

I never expected to see this. When I started my career, Object-Oriented Programming (OOP) was going mainstream. For many problems, it was and still is a natural way to modularize an application. It grew to (mostly) rule the world. Now it seems that the supremacy of objects may be coming to an end, of sorts.

I say this because of recent trends in our industry and my hands-on experience with many enterprise and Internet applications, mostly at client sites. You might be thinking that I’m referring to the mainstream breakout of Functional Programming (FP), which is happening right now. The killer app for FP is concurrency. We’ve all heard that more and more applications must be concurrent these days (which doesn’t necessarily mean multithreaded). When we remove side effects from functions and disallow mutable variables, our concurrency issues largely go away. The success of the Actor model of concurrency, as used to great effect in Erlang, is one example of a functional-style approach. The rise of map-reduce computations is another example of a functional technique going mainstream. A related phenomenon is the emergence of key-value store databases, like BigTable and CouchDB, is a reaction to the overhead of SQL databases, when the performance cost of the Relational Model isn’t justified. These databases are typically managed with functional techniques, like map-reduce.

But actually, I’m thinking of something else. Hybrid languages like Scala, F#, and OCaml have demonstrated that OOP and FP can complement each other. In a given context, they let you use the idioms that make the most sense for your particular needs. For example, immutable “objects” and functional-style pattern matching is a killer combination.

Difference between and

<input type="button" /> buttons will not submit a form -
In Ajax, it is for client side stuff.
They're generally used in conjunction with JavaScript as part of an AJAX application.

<input type="submit"> buttons will submit the form to the serveri side.
UserController/Action will process submitted information

Friday, April 17, 2009

Simplest example for JQuery validation

<html>

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js">
</script>
<script>

$(document).ready(function(){
$("#contactForm").validate();
});
</script>


<body>
<div id="container">
<form id="contactForm" method="" action="">
<label for="cemail">E-Mail</label>
<input id="cemail" name="email" size="25" class="required email" />
<input id="number" name ="number" class="required number"/>
<input class="submit" type="submit" value="submit"/>
</form>
</div>

</body>
</html>

Thursday, April 16, 2009

Boxy/JQuery

Source
Simple stuff only.

JQuery selector and getElementById

Javascript:
document.getElementById('product_id_01')

JQuery selector:
$('#product_id_01')[0]

Wednesday, April 15, 2009

How to debug Javascript/JQuery in VS2008

1. In browser: Enable script debugging
2. In VS 2008: Run the project first. Do not set breakpoint in your document first
3. In VS 2008: Check your solution explorer on the top. You will find [script document]. Double click to open html page and set breakpoint.

Tuesday, April 14, 2009

JQuery code for inline edit

<html>
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<span class="editName">Test</span>
<input id="newName" name="editName" style="display: none" type="text" />

<script type="text/javascript">
$(function(){
$("span.editName").click(function(){
$(this).hide();
$(this).next("input#newName").show().focus();
});
});
</script>
</body>
</html>

$(document).ready()

Traditionally Javascript events were attached to a document using an “onload” attribute in the tag of the page.

The $(document).ready() function takes a function as its argument. (In this case, an anonymous function is created inline—a technique that is used throughout the jQuery documentation.)

Understanding Selectors: the Backbone of jQuery

$(document);
The first option will apply the jQuery library methods to a DOM object (in this case, the document object).
$(’#mydiv’)
The second option will select every <div> that has the <id> attribute set to “mydiv”.
$(’p.first’)
The third option will select all of the <p> tags with the class of “first”.
$(’p[title="Hello"]‘)
This option will select from the page all <p> tags that have a title of “Hello”. Techniques like this enable the use of much more semantically correct (X)HTML markup, while still facilitating the DOM scripting required to create complex interactions.
$(’p[title^="H"]‘)
This enables the selection of all of the <p> tags on the page that have a title that starts with the letter H.

Try simple JQuery/javascript online

http://www.w3schools.com/JS/tryit.asp?filename=tryjs_text
Jquey reference online
<html>
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<script type="text/javascript">
document.write("Hello World!");
$(
function()
{
alert('hi');
}
)
</script>

</body>
</html>

Thursday, April 9, 2009

onload event in JQuery

<script type="text/javascript">
$(function() {
alert("This is equal to Form_Load in JQuery");
});
</script>

If getJSON in JQuery can not find exact signature method in Controller, it fails silently.... (ASP.NET MVC)

it fails silently....
Microsoft should put a couple of exclaimation marrk for this documentation somewherem, so we can see to save us sometime!!!!!!!!!!!!!!!!!!!!!!!!!

Example:
If you call getJSON in client side:
$.getJSON('/Home/GetList', { id: $("#country").val() },
You have to create an action in controller in following:
public JsonResult GetList(string id)
{
return Json(test.ToList());
}

But if you:
public JsonResult GetList(int id)
{
return Json(test.ToList());
}

You got nothing!!!!!!!!!!!!!!!!

Tuesday, April 7, 2009

Thursday, April 2, 2009

LINQ is pronounced link, "LIN Cue"

"link" is better to show what LINQ does.

Wednesday, April 1, 2009

How to create a text file on the fly, let user download it in ASP.NET

StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
sw.WriteLine("Name list");
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AppendHeader("content-disposition", "attachment;filename=teamlist.txt");
Response.Flush();
Response.Write(sb);
Response.End();

HTML encode link, helper to show code in blog

Link

Codes example for why use Lambda: how to find a distinct id list, and pass it into another method

Before Lambda:
List<Person> result = GetFromSomeWhere();

List<string> distinctids= new List<string>();
foreach (Person one in result)
{
if (!distinctids.Contains(one .Id.ToString()))
distinctids.Add(one .Id.ToString());
}

foreach (string id in distinctids)
{
DisplayPerson(id);
}

After:
List<Person> result = GetFromSomeWhere();
var result = result.Select(p=> p.Id).Distinct().ToList() ;
result.ForEach(id=>DisplayPerson(id));