Wednesday, June 30, 2010

Jquery Syntax

$(this).hide()
Demonstrates the jQuery hide() function, hiding the current HTML element.

$("#test").hide()
Demonstrates the jQuery hide() function, hiding the element with id="test".

$("p").hide()
Demonstrates the jQuery hide() function, hiding all

elements.

$(".test").hide()
Demonstrates the jQuery hide() function, hiding all elements with class="test".

$("p.test").hide()
hides all paragraphs with class="test

$("p#demo").hide()
hides the first

element with id="demo

jQuery uses a combination of XPath and CSS selector syntax.


$(document).ready(function(){
--- jQuery functions go here ----
});
This is to prevent any jQuery code from running before the document is fully loaded (is ready).

jQuery Attribute Selectors
jQuery uses XPath expressions to select elements with given attributes.

$("[href]") select all elements with an href attribute.

$("[href='#']") select all elements with an href value equal to "#".

$("[href!='#']") select all elements with an href attribute NOT equal to "#".

$("[href$='.jpg']") select all elements with an href attribute that ends with ".jpg".


$("ul li:first") The first

  • element of each

      $("[href$='.jpg']") All elements with an href attribute that ends with ".jpg"
      $("div#intro .head") All elements with class="head" inside a
      element with id="intro"
  • Jquery

    jQuery is a library of JavaScript Functions.
    jQuery library contains the following features:

    HTML element selections
    HTML element manipulation
    CSS manipulation
    HTML event functions
    JavaScript Effects and animations
    HTML DOM traversal and modification
    AJAX
    Utilities

    If you don't wanna store jquery in Project then you can ref it through Microsoft or Google
    Google CDN



    Microfost CDN




    Tuesday, June 29, 2010

    Template

    In order to use your faviourite templates. you could export template and use it when ever required.
    After created a project or template you can export the template
    File -> Export Template
    this will create a zip file in the exported templates folder for VS

    now you would see this template everytime you create a new projects.

    Monday, June 28, 2010

    VS Add Ins

    Aggiorno ASP.Net refactoring tool and best practices
    AnkhSVN – Provides a Subversion client for Visual Studio
    Code Rocket - Pseudocode and flowchart design and visualization.
    CodeRush - Refactoring and productivity plugin
    CopyAsHTML - Takes source code and creates an HTML markup that preserves indentation and coloring.
    Designbox - Adds a toolbox that lets you associate initial property values with controls
    Dotfuscator – Provides tools to help prevent reverse engineering
    Koders – Adds a search plug-in to search the Koders database
    PhatStudio – File navigation within a Visual Studio solution by typing partial filenames, and header switch
    ReSharper - Refactoring support for .NET languages
    Software Diagnostics Developer Edition - an integrated recorder, debugger and profiler for system dynamics
    TracExplorer - Trac integration for Visual Studio 2005 and 2008
    Visual Assist - Refactoring and code navigation support for native C++ and .NET (VC6/VS2003/VS2005/VS2008/VS2010)
    VisualSVN - Subversion integration for Visual Studio 2003/2005/2008.
    VsTortoise - A free TortoiseSVN add-in for Microsoft Visual Studio 2005/2008/2010
    HgSccPackage - Mercurial Source Control Plugin for Visual Studio 2008/2010
    VisualHG - Mercurial Source Control Plugin for Visual Studio 2005/2008/2010
    XMLSpy – Integrates the XMLSpy IDE into Visual Studio
    Bugnet Explorer Suite - Integrates Bugnet Issue and Project Management into Visual Studio and SVN
    Tabs Studio - Provides multiple tab rows and customizable tab grouping. ($34, 30 day free trial)
    SharpSort – C# source code members sorting and grouping
    UModel - Integrates support for all 14 UML diagram types and code engineering functionality directly in Visual Studio. (VS2005/VS2008/VS2010)
    WinGDB – Debug with GDB directly from Visual Studio. Remote Linux (via SSH), MinGW. Cygwin, embedded systems.
    wave-vs.net – Plugin to enable Remote Pair Programming in Visual Studio, supports Visual Studio 2008 and Visual Studio 2010

    TestDriven.NET
    GhostDoc
    Smart Paster
    CodeKeep
    PInvoke.NET
    VSWindowManager PowerToy
    WSContractFirst
    VSMouseBindings
    CopySourceAsHTML
    Cache Visualizer
    Wrapping It Up


    more fererence:http://msdn.microsoft.com/en-us/magazine/cc300778.aspx


    CodeRush - Of course. It's the bomb, enough said.
    Peter Blum's ADME - ASP.NET Design Mode Extender (“ADME”) helps custom controls to provide a better design mode interface. This supports his Validation Controls, which rock, but also controls that you might write that need richer Design Mode Support.
    CodeSmith Explorer - Generate CodeSmith code and templates directly from VS.NET
    CopySourceAsHtml - Better than a Macro, this Add-In puts syntax-highlighed HTML on your clipboard. Now it supports "Embedded Styles" for use in BlogJet and other tools.
    GhostDoc - Here's an Add-In I'd overlooked previously, now in it's 1.2 version. GhostDoc attempts to generate C# documentation that can be gleaned from the name and type of methods and properties. Roland Weigelt has big plans for version 1.30 that will include customizable text and rules. One to watch, and while it sometimes guesses wrong, it's a completely unique Add-In worth your download.
    devMetrics - devMetrics is a free tool for measuring various attributes of your C# code so that you can accurately assess your product for quality and maintainability. I use it to measure cyclomatic complexity and abuse people during code reviews.
    QuickCode.NET - This has been largely supplanted by CodeRush, but if you don't want to pay as much, this cool tool gives you phrase expansion and a surprising number of code expansions available on their user forum.
    Mindreef SOAPscope - The original. The glory forever, this is more than an Add-In, it's a complete XML Web Services design studio. It's a bargain and works even better when setup in a workgroup. It keeps a database of all Web Services traffic, but it's more than a sniffer. It also analyzes data for WS-I compliance and allows for record and replay of messages. "It's Tivo for Web Services!"
    NUnit Addin, now TestDriven.NET - If you're serious about TDD, stop fooling with NUnitGui and Attach Process and start using TestDriven.NET. It's a simple as Right-Click -> Test With -> Debugger.
    pinvoke.net - Adam Nathan continues to innovate with an add-in that lets you "Insert PInvoke Signature" from the VS.NET Editor by communiating with a server-side repository with best-practice signatures to make calling unmanaged code a breeze. Also, be sure to visit the PInvoke.NET Wiki.
    Reflector as an AddIn - A joint effort, run Lutz's unbelievable decompiler/explorer with Jamie's Add-In support. (There's a number of other slick, but alpha-quality addins at that link as well, including FxCop as an AddIn.)
    Regions AddIn - Finally, something useful from CodeProject, this add-in helps organize your code with a simple Right-Click -> Add To New Region and Right-Click -> Add To Existing Region. You'll wonder how you lived without it!
    Unleash it! - The great ASP.NET deployment tool with the unfortunate name. Formerly known as WebDeploy, this Add-In lets you deploy your ASP.NET application using whatever it takes. Now with plugin support!
    WS Contract-First - Christian Weyer leads the pack with custom Web Service code generation, and coming soon, generation of WSDL itself from Message-based XSD. How's that for SOA and contract-first development?
    VSCmdShell - Open a Command Prompt within a Visual Studio.NET 2003 Docked Toolbox Window!
    CommentReflower - Really detail-oriented? This tool reformats your code comments to your specifications.
    OnlineSearch - Search the Internet and Google directly from VS.NET!


    ReSharper


    MZ-Tools is also pretty feature rich...
    http://www.mztools.com/v4/features.htm

    CruiseControl.Net

    Thursday, June 24, 2010

    Read /write NULL Datetime in Sql Server by C#

    When you have to insert or read NULL datetiem from sql server then in that case.

    Use Namespace:using System.Data.SqlTypes;

    declare a variable SqlDateTime sqlNullDate;

    for INSERT
    if (txtSessionStartDate.Text == "")
    sessionsOBJ.sDate = sqlNullDate;
    else
    sessionsOBJ.sDate = Convert.ToDateTime(txtSessionStartDate.Text);

    and read would work normally.

    Tuesday, June 22, 2010

    To get the Latitude Longitude for any location

    Type below for XML response

    http://maps.google.com/maps/api/geocode/xml?address=1600+Pennsylvania+Ave,+Washington+D.C.&sensor=false


    for JSON
    http://maps.google.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true_or_false


    or type
    http://geocoder.us/demo.cgi?address=4950+stevenson+blvd+%2Cfremont+ca+94538
    to get the lat and log

    for details read below article
    http://code.google.com/apis/maps/documentation/geocoding/index.html#Geocoding
    http://www.4guysfromrolla.com/articles/060210-1.aspx

    Image Generator control in ASP.Net 3.5

    Storing images in database BLOB field and displaying it on aspx page is one of the common tasks we do in asp.net projects. Asp.Net itself does not have an in build control to bind the image stored in database. To display an image stored in database, we will write an HttpHandler which will fetch the image from database and do a binary write. We all know that doing a binary write will become cumbersome when the number of images increases and the number of users becomes high. This week Microsoft have released a new control called ASP.NET Generated Image control to display image in ASP.Net page.

    Download the control (Microsoft.Web.GeneratedImage.dll) from
    http://aspnet.codeplex.com/releases/view/16449

    This control can be used to display image faster, we can cache the generated image and we can do transformation on the generated image. To display the image, this control uses an Image HttpHandler which can accept parameters using NameValueCollection object. This Image HttpHandler is similar to normal HttpHandler which inherits an abstract class called ImageHandler. This ImageHandler abstract class internally inherits IHttpHandler.



    public class ImageHandler1 : ImageHandler {



    public ImageHandler1() {

    // Set caching settings and add image transformations here

    }



    public override ImageInfo GenerateImage(NameValueCollection parameters) {

    return new ImageInfo();

    }

    }

    The implementation is really simple. Read the image from database as a byte array and convert the byte array to Microsoft.Web.ImageInfo object for the image to display. This object will come as a part of the control dll we are downloading. ImageInfo object has 2 overloaded constructors, one will take Image object and the other will take a byte array as an argument. We can pass the parameters to this handler by a collection called Parameters in GeneratedImage control. With this information, we will see how we can use this control to display images.

    refere below article for more details...
    http://www.codedigest.com/Articles/ASPNET/119_New_Image_Generator_control_in_ASPNet_35.aspx

    Monday, June 21, 2010

    Geocoding

    Read this article for better understanding.

    http://www.4guysfromrolla.com/articles/051910-1.aspx

    Geocoding is the process of finding associated geographic coordinates (often expressed as latitude and longitude) from other geographic data, such as street addresses, or zip codes (postal codes). With geographic coordinates the features can be mapped and entered into Geographic Information Systems, or the coordinates can be embedded into media such as digital photographs via geotagging.

    Reverse geocoding is the opposite: finding an associated textual location such as a street address, from geographic coordinates.

    A geocoder is a piece of software or a (web) service that helps in this process.

    A simple method of geocoding is address interpolation. This method makes use of data from a street geographic information system where the street network is already mapped within the geographic coordinate space. Each street segment is attributed with address ranges (e.g. house numbers from one segment to the next). Geocoding takes an address, matches it to a street and specific segment (such as a block, in towns that use the "block" convention). Geocoding then interpolates the position of the address, within the range along the segment

    Type
    http://maps.google.com/maps/api/geocode/xml?address=1600+Pennsylvania+Ave,+Washington+D.C.&sensor=false
    in the address bar and you would get the xml response

    Thursday, June 17, 2010

    Element of Web Config





    cookieless="true|false"
    timeout="number of minutes"
    stateConnectionString="tcpip=server:port"
    sqlConnectionString="sql connection string"
    stateNetworkTimeout="number of seconds"/>

    A very useful article at
    http://msdn.microsoft.com/en-us/library/h6bb9cz9(VS.71).aspx

    Wednesday, June 16, 2010

    Favorites Icon

    The Favorites Icon will show up next to the URL (the http:// web address) in your web browser near the top of the window

    Tuesday, June 15, 2010

    Create a Service Account for an ASP.NET 2.0 Application

    http://msdn.microsoft.com/en-us/library/ff649309.aspx

    Find Framework installed

    In this case, you might wonder what .Net framework version you have or do you have the so-called latest .Net 3.5 framework?
    OK, general end users can use either one of these ways to check the .Net framework version:

    Query the User Agent String of Internet Explorer web browser. This is the easier way, I think, as every Windows bundled with IE! Although you need to remember this simple, one line JavaScript:
    javascript:alert(navigator.userAgent)

    Other way is to get into Registry:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP

    3 Way is to check through Windows Application:

    Environment.Version property of .Net framework. For example, this simple C# source code can be compiled to a .Net console program that shows .Net framework version installed: using System;

    class Version
    {
    public static void Main()
    {
    Console.WriteLine();
    Console.WriteLine(".Net Framework Version {0}",
    Environment.Version.ToString());
    }
    }

    Monday, June 14, 2010

    Databound Password TextBox field is blank on page load

    I have a databound TextBox in a FormView control with it's TextMode set to Password. My issue is that when the page loads the password field is empty. This is causing problems of clearing out the password when you hit save.

    Does anyone know a possible work around to make a databound TextBox inside a FormView work as desired?

    Saturday, June 12, 2010

    ENCTYPE

    In most cases you will not need to use this attribute at all. The default value (i.e. if you don't use this attribute at all) is "application/x-www-form-urlencoded", which is sufficient for almost any kind of form data. The one exception is if you want to do file uploads. In that case you should use "multipart/form-data". See file uploads for more details.

    ENCTYPE determines how the form data is encoded. Whenever data is transmitted from one place to another, there needs to be an agreed upon means of representing that data. Music is translated into written music notation, English is written using letters and punctuation. Similarly, there needs to be an agreed on way of presenting the form data so it's clear that, for example, there is a field called "email" and its value is "raha@idocs.com".

    Attribute for FORM ...
    ENCTYPE = "multipart/form-data" | "application/x-www-form-urlencoded" | "text/plain"

    Friday, June 11, 2010

    Extension Methods

    How often do you want to modify existing classes to have extra methods? Quite often. Right? When you have source code of the classes under consideration at your hand then things are easy. You probably just add the extra methods to those classes. What if you don't have source code? Well. In such cases one approach is to inherit the existing classes and add extra methods to the child classes. However, this way may not be always correct and possible in terms of your application design and OO principles. Luckily, C# offers a quick way to extend your class functionality through a feature known as Extension Methods. Extension methods allow you to extend existing types without inheriting them

    Will explain with example
    public static class DateTimeHelper
    {
    public static DateTime ToIST(this DateTime dt)
    {
    DateTime utc = dt.ToUniversalTime();
    return utc.AddMinutes(330);
    }

    public static bool IsDate(this string s)
    {
    DateTime dt;
    return DateTime.TryParse(s, out dt);
    }
    }


    there is static class named DateTimeHelper
    All the extension methods must reside inside a static class
    The extension methods themselves must be static


    The ToIST() static method is an extension method that returns a DateTime instance. Observe how the parameter of the method is specified. An extension method can have any number of parameters but the first parameter indicates the data type to which that extension is applicable. In case of ToIST() method we specify that this method is an extension method of DateTime structure. The ToIST() method simply adjusts the date and time with required offset.

    The IsDate() method is another extension method that will be applicable to string data type. Inside it checks if the supplied string is a valid date and returns a Boolean value.

    Now, if you use DateTime structure then the Visual Studio will show you ToIST() method in the IntelliSense. Similarly, IsDate() method will be shown for string class.

    More about extension methods
    Though extension methods allow you to quickly extend an existing type this feature should not be used extensively as a replacement to other elegant approaches. Additionally, the following points about extension methods are worth noting.

    Extension methods can chain themselves. For example you may write something like this:
    dt.ToIST().ToDDMMYYYY()
    The ToIST() and ToDDMMYYYY() are assumed to be extension methods.
    Extension methods can be accessed only when its namespace is in scope
    If an extension method has the same signature as any of the instance method of the class it extends then the instance methods take precedence
    If two extension methods of a type have same signature them they must be called like normal static methods. For example, if you define two extension methods with same name and signature in two classes say DateTimeHelper1 and dateTimeHelper2, then they can be called like this - DateTimeHelper1.ToIST(dt)

    Wednesday, June 9, 2010

    XML

    XML stands for EXtensible Markup Language
    XML is a markup language much like HTML
    XML was designed to carry data, not to display data
    XML tags are not predefined. You must define your own tags
    XML is designed to be self-descriptive
    XML is a W3C Recommendation

    Reading/Writing XML

    To Read Data from the XML file

    DataSet ds = new DataSet();
    ds.ReadXml(Server.MapPath("XML\\XMLFile.xml")); //Path of XML file
    GridView1.DataSource = ds;
    GridView1.DataBind();

    And to Write back the XML Date
    DataSet ds = new DataSet();
    ds.ReadXml(Server.MapPath("XML\\XMLFile.xml"));
    ds.WriteXml("XMLFile1.xml");

    I am just creating the dataset from the existing file

    Improving the Performance of Ajax enabled web page

    ASP.NET Ajax 3.5 SP1 contains a new feature that enables the application developer to combine scripts in order to reduce the number of downloaded files. But in order to do that, the developer must have a way of discovering what scripts are being used in a page or application

    Details can be found on this link:

    http://weblogs.asp.net/bleroy/archive/2008/06/12/script-reference-profiler.aspx

    Watct viedo for using it:
    http://www.asp.net/aspnet-in-net-35-sp1/videos/using-script-combining-to-improve-ajax-performance

    Add below to page to find the running scripts



    run the page again and it will show all the scripts that take time collect them and paste then in

    Tuesday, June 8, 2010

    Yelp Features

    *retrieve trusted business review and rating information for a particular geographic region or location.

    * display trusted review and rating information for a particular business.

    * determine accurate neighborhood name information for a particular location.

    * display pictures of highly rated local businesses and of the top reviewers for that business.

    * determine a particular business' review and rating information based on the phone number for that business.

    Monday, June 7, 2010

    Generic

    What are Generic and when to use it.

    A perfect example of where we would need Generics is in dealing with collections of items (integers, strings, Orders etc.).
    We can create a generic collection than can handle any Type in a generic and Type-Safe manner.
    For example, we can have a single array class that we can use to store a list of Users or even a list of Products, and when we actually use it, we will be able to access the items in the collection directly as a list of Users or Products, and not as objects (with boxing/unboxing, casting).


    Previous problems
    1)It requires that you store everything in it as an object
    2)You need to cast up in order to get your object back to its actual Type
    3)Performance is really lacking, especially when iterating with foreach()
    4)It performs no type safety for you (no exceptions are thrown even if you add objects of different types to a single list)

    System.Collections.ArrayList list = new System.Collections.ArrayList();
    list.Add("a string");
    list.Add(45); //no exception thrown
    list.Add(new System.Collections.ArrayList()); //no exception
    foreach(string s in list) { //exception will be thrown!
    System.Console.WriteLine(s);


    The ideal situation is for us to be able to create this generic collection functionality once and never have to do it again
    -----------------
    Generic Class

    public class Col
    {
    T t;
    public T Val{get{return t;}set{t=value;}}
    }

    "Col" is our first indication that this Type is generic

    This Type placeholder "T" is used to show that if we need to refer to the actual Type that is going to be used when we write this class, we will represent it as "T"

    Notice on the next line the variable declaration "T t;" creates a member variable with the type of T, or the generic Type which we will specify later during construction of the class

    final item in the class is the public property. Again, notice that we are using the Type placeholder "T" to represent that generic type for the type of that property. Also notice that we can freely use the private variable "t" within the class.


    In order to use this class to hold any Type, we simply need to create a new instance of our new Type, providing the name of the Type within the "<>" brackets and then use that class in a Type-safe manner. For example:


    public class ColMain {
    public static void Main() {
    //create a string version of our generic class
    Col mystring = new Col();
    //set the value
    mystring.Val = "hello";

    //output that value
    System.Console.WriteLine(mystring.Val);
    //output the value's type
    System.Console.WriteLine(mystring.Val.GetType());

    //create another instance of our generic class, using a different type
    Col myint = new Col();
    //load the value
    myint.Val = 5;
    //output the value
    System.Console.WriteLine(myint.Val);
    //output the value's type
    System.Console.WriteLine(myint.Val.GetType());

    }
    }

    Thursday, June 3, 2010

    IDisposable Interface

    DLL used:mscorlib.dll

    The primary use of this interface is to release unmanaged resources. The garbage collector automatically releases the memory allocated to a managed object when that object is no longer used. However, it is not possible to predict when garbage collection will occur. Furthermore, the garbage collector has no knowledge of unmanaged resources such as window handles, or open files and streams

    Use the Dispose method of this interface to explicitly release unmanaged resources in conjunction with the garbage collector. The consumer of an object can call this method when the object is no longer needed.

    Tuesday, June 1, 2010

    Differences Between Web.Config and Machine.Config

    The Differences Between Web.Config and Machine.Config
    Web.config files specify configuration settings for a particular web application, and are located in the application's root directory; the machine.config file specifies configuration settings for all of the websites on the web server, and is located in $WINDOWSDIR$\Microsoft.Net\Framework\Version\CONFIG.

    Web.Config Encryption

    Encryption is possible in 2 ways

    1) programatically
    2) aspnet_regiis.exe, a command-line program

    and the following sections can be encrypted.

    , , and .

    Each of these sections can optionally be encrypted, either programmatically or through aspnet_regiis.exe, a command-line tool. When encrypted, the scrambled text is stored directly in the configuration file. For example, if we were to encrypt the section above the resulting Web.config file might look like the following: (Note: a large chunk of the has been removed for brevity.)

    e.g



    AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAed...GicAlQ==




    There are some configuration sections that you cannot encrypt using this technique:












    In order to encrypt these configuration sections you must encrypt the value and store it in the registry. There's an aspnet_setreg.exe command-line tool to help along with this process

    Programmatically Encrypting Configuration Sections
    The System.Configuration.SectionInformation class abstractly represents a configuration section. To encrypt a configuration section simply use the SectionInformation class's ProtectSection(provider) method, passing in the name of the provider you want to use to perform the encryption. To access a particular configuration section in your application's Web.config file, use the WebConfigurationManager class (in the System.Web.Configuration namespace) to reference your Web.config file, and then use its GetSection(sectionName) method to return a ConfigurationSection instance. Finally, you can get to a SectionInformation object via the ConfigurationSection instance's SectionInformation property.

    protected void UnProtect_Click(object sender, EventArgs e)
    {
    UnProtectSection("appSettings");
    }

    protected void Protect_Click(object sender, EventArgs e)
    {
    ProtectSection("appSettings",
    "DataProtectionConfigurationProvider");
    }

    private void ProtectSection(string sectionName, string provider)
    {
    Configuration config =
    WebConfigurationManager.
    OpenWebConfiguration(Request.ApplicationPath);

    ConfigurationSection section = config.GetSection(sectionName);

    if (section != null && !section.SectionInformation.IsProtected)
    {
    section.SectionInformation.ProtectSection(provider);
    config.Save();
    }
    }

    private void UnProtectSection(string sectionName)
    {
    Configuration config =
    WebConfigurationManager.
    OpenWebConfiguration(Request.ApplicationPath);

    ConfigurationSection section = config.GetSection(sectionName);

    if (section != null && section.SectionInformation.IsProtected)
    {
    section.SectionInformation.UnprotectSection();
    config.Save();
    }
    }