Friday, April 29, 2011

Hackers vs. Coders

http://blog.amirkhella.com/2011/04/27/hackers-and-coders/
Hackers solving user problems, rather than solving implementation problems.

Why programmers are not paid in proportion to their productivity

http://www.johndcook.com/blog/2009/12/23/why-programmers-are-not-paid-in-proportion-to-their-productivity/
Programmers are most effective when they avoid writing code. They may realize the problem they’re being asked to solve doesn’t need to be solved, that the client doesn’t actually want what they’re asking for. They may know where to find reusable or re-editable code that solves their problem. They may cheat. But just when they are being their most productive, nobody says “Wow! You were just 100x more productive than if you’d done this the hard way. You deserve a raise.” At best they say “Good idea!” and go on.  It may take a while to realize that someone routinely comes up with such time-saving insights. Or to put it negatively, it may take a long time to realize that others are programming with sound and fury but producing nothing

Thursday, April 28, 2011

How to block/detect Adblock by jQuery


<div class="myTestAd" style=" text-align:center;margin:10px">
 <!-- advert code goes here -->
</div>


function TestPage() {
    if ($('.myTestAd').height() == 0)
        alert("You are blocking my beautiful adverts, you swine!");
}

$(TestPage);

http://thepcspy.com/read/how_to_block_adblock/

How to use jQuery Wildcard/Start with Selector

Start with:
$("[id^=partofID]").show();

Wildcard:
$("[id*=partofID]").show();
Attribute Starts With Selector 
[name*="value"]

ASP.NET MVC: Create a Custom ActionResult to return XML

http://www.dotnetcurry.com/ShowArticle.aspx?ID=682

How to setup SSL(HTTPS) for ASP.NET development (MVC&WebForms)

Very detailed steps with screen shot

http://blogs.msdn.com/b/rickandy/archive/2011/04/22/better-faster-easier-ssl-testing-for-asp-net-mvc-amp-webforms.aspx

Wednesday, April 27, 2011

What is double question mark in C#?

 The ?? operator is called the null-coalescing operator.
It returns the left-hand operand if it is not null; otherwise it returns the right operand


        int? x = null;
        // y = x, unless x is null, in which case y = -1.
        int y = x ?? -1
        // In here y = -1
        x = 1;
        y = x ?? -1
        // In here y = 1



Reference:

ASP.NET WebForms Partial page refresh by jQuery

Partial page refresh using jQuery

Tuesday, April 26, 2011

How to solve bing map ajax over SSL https problem, "Microsoft is undefined?"

Add s=1 parameter in the URL reference
https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&s=1

How to show a pushpin with information box by Bing Maps V7.0

How to show a pushpin with information box by Bing Maps V7.0
    <div class='mapb'><a href='#'>Show Map</a></div>
    <div id='BingMapDiv'/>



    <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0">
    </script>
    <script type="text/javascript">
        var map = null;
        var bingmapkey = "<%=Registration.GeoLocation.BingMapKey%>";
        var pinlatlon = "45.410309,-75.674057";
        var pindescription = 'Push pin title';


        function GetMap() {
            map = new Microsoft.Maps.Map(document.getElementById("BingMapDiv"), { credentials: bingmapkey, showCopyright: false, showDashboard: false, showScalebar: false, showMapTypeSelector: false });

            var pinPoint = pinlatlon;
            var pinlocation = map.getCenter();
            if (pinPoint != "") {
                pinlocation = new Microsoft.Maps.Location(pinlatlon.split(",")[0], pinlatlon.split(",")[1]);
            }

            var pin = new Microsoft.Maps.Pushpin(pinlocation);
            pinInfobox = new Microsoft.Maps.Infobox(pinlocation, { title: 'Title', visible: true, description: pindescription });
            Microsoft.Maps.Events.addHandler(pin, 'click', displayInfobox);
            Microsoft.Maps.Events.addHandler(map, 'viewchange', hideInfobox);

            map.entities.push(pin);
            map.entities.push(pinInfobox);

            map.setView({ center: pinlocation, zoom: 10 });
        }

        function displayInfobox(e) {
            pinInfobox.setOptions({ visible: true });
        }
        function hideInfobox(e) {
            pinInfobox.setOptions({ visible: false });
        }

        $('.mapb').live('click'function () { $('#BingMapDiv').toggle(); if ($('#BingMapDiv').is(':visible')) GetMap(); });

    </script>


How to force Visual Studio to regenerate the .designer file

Solution 1:
Check html view header if CodeBehind existed
 CodeBehind="~/Your.aspx.cs"

Solution 2:
Reformat or modify html view and check if anything syntax problem for html tags

Solution 3:
   1. Delete the designer.cs file from your project
   2. Rightclick your main aspx file and select “Convert to Web Application“.

Reference:



Monday, April 25, 2011

Complexity is the enemy

It turns out that, much like it's easier to write a long blog post than it is to make the same point succinctly, it's difficult to write software that is straightforward. This is easiest to see in programming langauge design; new languages by novices tend to have lots of features, while few have the crisp clarity of C. In today's programs it's frequently related to how many objects are involved; in distributed systems it's about how many moving parts there ar

Tech Notes: Complexity is the enemy

How to get checkboxes values in jQuery

 if ($('#YourID').is(':checked')) {
            //Do something
        }




Reference:
:checked Selector
http://api.jquery.com/checked-selector/

What is Boolean values in SQL Server?

TRUE is converted to 1 and FALSE is converted to 0.
Reference:

Creating an Up and Down Voting User Interface

Creating an Up and Down Voting User Interface

Sunday, April 24, 2011

How Many Websites are there on the Internet?

156 million

What is blog Slug, URL friendly version of the post title

A slug is a few words that describe a post or a page. Slugs are usually a URL friendly version of the post title (which has been automatically generated by WordPress), but a slug can be anything you like. Slugs are meant to be used with permalinks as they help describe what the content at the URL is.
Example post permalink: http://wordpress.org/development/2006/06/wordpress-203/
Reference:
http://codex.wordpress.org/Glossary

Saturday, April 23, 2011

8 Great Websites to Learn Step-by-Step jQuery

http://webdesigneraid.com/8-great-websites-to-learn-step-by-step-jquery/

Sequence diagram for ASP.NET application events in Global.asax

There are two types of events in global.asax file in your application domain:
  1. Events which get called for every request.
  2. Events only get invoked under certain conditions.
For the first type of events which occur for every request, they get executed in the following order:
  1. Application_BeginRequest(): This is called at the start of every request.
  2. Application_AuthenticateRequest(): This is called just before authentication is performed. You could add your own authentication logic in this method to provide custom authentication.
  3. Application_AuthorizeRequest(): This is called when the authentication stage is completed. It's executed at the stage to determine user privileges and permissions. You could add custom code to assign user special privileges.
  4. Application_ResolveRequestCache(): This is often used in conjunction with output caching. With output caching, the rendered HTML of a page is reused without executing its code. However, this event handler still runs.
  5. ----------Then the request is sent to its assigned handler. For example, an ASP.NET web form page is sent to compilation (if it is due) and instantiation.----------
  6. Application_AcquireRequestState(): This is called just before session-specific data is retrieved for the client and is used to populate Session Collection.
  7. Application_PreRequestHandlerExecute(): This is called before the appropriate HTTP handler executes the request.
  8. ----------The handler now executes the request. The code of your ASP.NET web form page is now executed and the HTML is now rendered.----------
  9. Application_PostRequestHandlerExecute(): This is called just after the request is handled by its appropriate HTTP handler.
  10. Application_ReleaseRequestState(): This method is called when the session-specific information is about to be serialized from the Session Collection so that it's available for the next request.
  11. Application_UpdateRequestCache(): This is called just before information is added to the output cache. If you have enabled output caching for your web page, it's now the time ASP.NET insert the rendered HTML into the cache.
  12. Application_EndRequest(): This is called at the end of the request, right before the objects are released and reclaimed. It's the place to add your cleanup code.
This diagram below can help you grab a better insight of this cycle:
Blog Application Events Diagram

In general, developers are more likely to provide handling code for Application_BeginRequest(log information for analysis, routing, etc.), Application_AuthorizeRequest(custom authorization and privilege etc.) and Application_EndRequest(log information for analysis, cleanup, etc.).
For the second type of application events which do not fire upon every request, there are six of them:
  1. Application_Start(): This is called when the application first starts up and the application domain is created. This is the place for you to insert application-wide initialization code. For example, you may want to add code here which load and cache data, load some application-wide configuration setting, navigation trees and other static data and information which will stay persistent throughout the lifetime of your application.
  2. Session_Start(): This method is invoked each time a new session begins, This is often used to initialize user-specific information. Some developers also use this to count the number of current active user session in the application.
  3. Application_Error(): This is invoked whenever an unhandled exception occurs in the application. You may want to use this to perform some custom error handling logic application-wide.
  4. Session_End(): This is called when a user session ends. A session ends when your code releases it explicitly or its idle time exceeds the set expiry timeout (by default 20 minutes, you may change it in your web.config). Developers typically add code here to clean up any related data. Note that this method is only called if you are using in-process session state storage (InProc mode, not StateServer of SQLServer modes).
  5. Application_End(): This method is invoked just before an application ends. The end of an application can occur because IIS is shut down or the application is transitioning to a new domain in response to file updates or process recycling.
  6. Application_Disposed(): This method is called some time after the application is shut down and the garbage collector is about to reclaim the memory it occupies (just like other objects' disposal in .NET). Note that it is already too late to perform critical cleanup at this point of time. But you may want to add code here to verify that resources have been released as a last-ditch safe-proof.



http://www.freewebdevelopersite.com/2011/03/21/application-events-in-global-asax/

Friday, April 22, 2011

What is relationship between WebMatrix, Razor, ASP.NET Web Pages and MVC?



WebMatrix: a stack and a tool


Let’s start with WebMatrix.  The term is actually used is two ways:
  1. The WebMatrix stack contains a number of things that you get when you install it via WebPI:
    • The new ASP.NET Web Pages framework
    • The Razor templating engine
    • The WebMatrix tool (see #2)
    • IIS Express
    • SQL CE 4
  2. The WebMatrix tool, which lets you perform various tasks:
    • Create web apps that use the Web Pages framework and the Razor templating engine
    • Install existing sites from the Web Gallery.  Note that those sites don’t have to use the Web Pages framework, and in fact most don’t (e.g. ScrewTurn wiki, Subtext)
    • Manage IIS express
    • Manage SQL CE 4 databases
Key point: the WebMatrix tool is not by any mean the only way to create Web Pages apps.  In fact, the Web Pages framework was designed to be very notepad friendly.  On the other end of the tooling spectrum, it will later be fully supported by Visual Studio.

Razor: a templating engine


At its root, Razor is just a templating engine, which is best compared to something like T4.  It is also comparable to the aspx and Spark engines.  The best way to describe it in its most general sense is:
  • It takes as input:
    • a template file (with a .cshtml or .vbhtml extension)
    • some input data: in web scenario, this includes things like an HTTP request, but this is not a requirement
  • It produces some output string: in web scenario, this is typically a piece of HTML that then gets sent as an HTTP response, but it could be anything.
So as an example, you could envision a very simple command line tool that would read an input file and some parameters, and write out the result of running the template on that input.  Note that everything I wrote here applies both to Razor and to something like T4.
Key point: Razor in itself is not tied to MVC nor to the Web Pages framework, and is not even really tied to web applications.
Note: check out Andrew Nurse’s blog for lots of technical details about Razor.

ASP.NET Web Pages: a simple framework to write ASP.NET web apps


WebMatrix introduces ASP.NET Web Pages, which gives users a simple and powerful new way of writing ASP.NET apps.  It is different from WebForms as it doesn’t use server controls.  It is also different from MVC as it doesn’t follow the MVC pattern.  Instead, it follows a much simpler ‘inline page’ model, where a page is basically an HTML page with some code added where needed.  In that sense, it is reminiscent of Classic ASP, but it is also very different in the sense that it has the full power of the .NET framework available behind it.  It also supports concepts like layout pages which make it much more flexible than the Classic ASP.
Where the discussion gets interesting is that the Web Pages framework uses Razor as its default templating engine.  However, it is not tied to Razor.  Potentially, you could use the aspx or Spark templating engines with the Web Pages framework.  At this point, we have mostly focused on using Razor with it, but it’s entirely conceivable that other templating engines would be supported later.
Key point: ASP.NET Web Pages uses Razor by default, but is not technically tied to it.

ASP.NET MVC


ASP.NET MVC is not part of the WebMatrix release, as it is a completely different framework with different goals (and this post is not about the pros and cons of the two, so I won’t go into that here!).  However, it ties into the story because the Razor templating engine will (soon) be made available as an MVC view engine.  As it should now be clear, this does not imply that you would be using ASP.NET Web Pages if you choose to use Razor as your MVC view engine.  All it means is that you’d be using the Razor syntax for your views instead of aspx (or Spark, …).  This has no bearing on how you write your controllers or other parts of your app.
Key point: Razor syntax will soon be available as an MVC view engine alternative


How WebMatrix, Razor, ASP.NET Web Pages and MVC fit together - Angle Bracket Percent - Site Home - MSDN Blogs

Generating RSS and ATOM Feeds In WebMatrix

Generating RSS and ATOM Feeds In WebMatrix

Asp.net MVC A-Z

Action:-Actions are like our general methods we are writing in C#,Controller can contain all actions which can send the response to the user or calling Views. Action(s) have return types ActionResult ii will return ViewResult for calling the View

Controller:-It is the Heart of Asp.net MVC, which take request for user and it will decide what view to render. It contain actions.
Model:-Model is like our normal .net component for write our business logic/validations etc.
View:-It is rednering User Interface, it contain 2 forms either .aspx(View) or .ascx(Partial View)
ViewEngineCollection:-It gives list of all register views


http://mvcframework.wordpress.com/2010/04/22/asp-net-mvc-a-z/

Thursday, April 21, 2011

8 useful sites for web developers

8 useful sites for web developers



Happy new year! 2011 is finally here. What about starting the new year with some absolutely awesome websites and tools to make your web developer life easier? I have compiled a must-read list for you.

Min.us: The easiest way to upload images


Any developer, designer or webmaster have to share images online with clients and co-workers. Min.us is an all new service that allow you to upload images extremely easily: Just drag and drop them into Min.us and the image will be saved on their servers. A short url will be automatically created so you can share it across the web.
» Visit Min.us

Wirify: Transform any web page into wireframes


Wireframes are extremely useful when designing a website. Wirify is a bookmarklet that allow you to instantly convert any web page into wireframes that you can study or use for your own work.
» Visit Wirify

CSS Resetr: View and compare CSS resets


CSS resets are a must have in any stylesheet in order to render differences between browsers. Since 2004, a lot of differents CSS resets has been published. So, which one is the best for your project? CSS Resetr let you compare the result of the most popular resets on a web page.
» Visit CSS Resetr

Head JS: Speed up your site with 2.30 kb of Javascript


Head JS is a simple and light (2.3 kb) script that will make your site faster by loading other scripts as images. Head JS can do a lot more to modernize your site: CSS3 support, dynamic CSS, etc.
» Visit http://headjs.com/

Copy Paste Character: Use special characters with ease


Special characters are often a pain to deal with, because they’re not on your keyboard, and because you don’t know the related ASCII code. Of course, you can grab an ASCII table and keep it on your desktop, or you can use a new service called Copy Paste Character: Simply click on the selected character to have it copied to your clipboard.
» Visit Copy Paste Character

DB Designr: Create database schemas online


Here is a very great tool to easily create database schemas online. No need to create an account, you can loggin using your Google account (Well, I guess any CWC reader have a Google account!)
» Visit DB Designr

Web 2 pdf convert: Convert any web page to PDF


Web2PDF Converter is a very useful tool that convert any webpage into a PDF file. It works great: I’ve converted 5 pages and all where the exact copy of the html version.
This very handy tool have more to offer: You can email an url and receive the PDF back. You can also add a bookmarklet to your browser for faster archiving.
» Visit web 2 pdf convert

Easily link your html page to your JS library


Are you tired of hunting the Internet in order to find the script tag for the latest version of the Javascript library of your choice? ScriptSrc.net has compiled all the latest versions of jQuery, Mootools, Prototype and more in a single page which lets you copy it in your browser clipboard with a single click.
» Visit ScriptSrc