HOME

Wednesday, February 29, 2012

About Coffee Script


CoffeeScript is a little language that compiles into JavaScript. Underneath all those awkward braces and semicolons, JavaScript has always had a gorgeous object model at its heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.
The golden rule of CoffeeScript is: "It's just JavaScript". The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime. You can use any existing JavaScript library seamlessly from CoffeeScript (and vice-versa). The compiled output is readable and pretty-printed, passes through JavaScript Lint without warnings, will work in every JavaScript implementation, and tends to run as fast or faster than the equivalent handwritten JavaScript.

Execute c# program in notepad and cmd? with out visual studio

Introduction
In this article you will learn to write your first C# program and compile it using the command-line C# compiler. I strongly recommend you read this article first to correctly install the .NET v1.1 SDK on your computer. The goal of this article is to get you comfortable with writing a C# program and compiling it. The code you type will be explained in later articles. So dont worry if you cant understand any code in this article.

As tradition goes the first program though is the Hello World program, which does nothing more but print a simple "Hello World" message on the console screen. Youll need a text editor (like Notepad) and the .NET v1.1 SDK installed on your computer to work with this example.
Let's begin!
Step 1: Start notepad from Start -> Program Files -> Accessories -> Notepad so that you can write the Hello World program. The program you write in C# is also called as source code.
Step 2: Write the Hello World program, you can either type the program shown below into notepad or just copy-paste it from this article.
/*
 HelloWorld.cs - First C# Program
 Written by - Saurabh Nandu
 Compilation:
 csc HelloWorld.cs
*/

public class HelloWorld
{
  public static void Main()
  {
    //Print Hello World
    System.Console.WriteLine("Hello World !");
  }
}
Note 1: C# is a case-sensitive language hence in C# class HelloWorld, class helloWorld and class helloworld are treated differently, so be very careful while typing and type exactly as shown !!
Note 2: Indenting (leaving spaces before each line), is not mandatory, but its a good practice since it makes it easier to read indented code.
Step 3: Once you have finished typing your program you should Save the source code file. In fact after making any changes to your source code, you should always save the file. To save the file for the first time in notepad click on
File menu -> Save As. In the Save As dialog select the directory from the Save In dropdown where you want to save your files, I generally save my files to C:\csharp, and then in the File name textbox, enter the file name as HelloWorld.cs (although you can provide any name you want but it should have an extension .cs). and click Save. Once you have saved the source code, and if you make any further modifications, in notepad use the Ctrl+S keyboard short-cut to save your source code file.
 

Figure 1: Notepad Save As dialog
Note 3: C# source code files are stored with the extension .cs.
Note 4: In notepad's Save As dialog, File name textbox, always enter the file name in quotes (" ") so that the file is saved with the correct *.cs extension, else on some operating systems if you miss the quotes the file is saved with the extension *.txt (default for text files) due to which your files may not compile.
Step 4: Since you have finished writing the source code its time to compile it. Since we are using a command-line compiler that ships with the .NET SDK, start the command prompt fromStart -> Program Files -> Accessories -> Command Prompt. Or go to Start -> Run, type cmd and press enter.
Note 5: If you have installed Visual Studio.NET then start the command prompt from Start -> Program Files -> Microsoft Visual Studio .NET -> Visual Studio .NET Tools -> Visual Studio .NET Command Prompt. We use this prompt since it has the correct path settings for the C# compiler. Refer to the Installing the .NET v1.1 SDK article for more information on setting paths.
Now from the command prompt navigate to the directory where you have stored the source code file by issuing the following DOS commands.

cd\ - To navigate to the root of the drive
cd csharp - To navigate to the csharp directory.

Once you are in the csharp directory where you saved the source code file earlier, its time to run the C# Compiler csc.exe. Issue the following command to compile our HelloWorld.csprogram:

csc HelloWorld.cs 

You should see the output similar to that shown in figure below indicating the file was successfully compiled.
 
Figure 2: Compilation of C# source code
Step 5: If the compilation of the source code was successful then a new executable (Exe) file by the name HelloWorld.exe will be created in the directory you compiled the source code.
To execute the program simply type the name of the executable file at the command prompt and you will see the output of the program (Hello World !) as shown below.

Figure 3: Executing Hello World application
Congratulations you have successfully compiled your first C# program! Its time for you to proceed further and learn the C# language.
Points to Remember
1) C# code can be written in any text editor like notepad.
2) C# Source Code files are saved with the extension .cs.
3) C# is a case-sensitive language so you have to be careful while typing.
4) C# runs on the .NET Platform, hence you need to install the .NET SDK in order to compile C# programs.
5) The C# compiler is contained within the file csc.exe, which generally resides in the C:\windows\Microsoft.NET\Framework\v1.0.4322 directory.

View State Problem in Asp.Net

 ASP.NET view state, in a nutshell, is the technique used by an ASP.NET Web page to persist changes to the state of a Web Form across postbacks. In my experiences as a trainer and consultant, view state has caused the most confusion among ASP.NET developers. When creating custom server controls or doing more advanced page techniques, not having a solid grasp of what view state is and how it works can come back to bite you. Web designers who are focused on creating low-bandwidth, streamlined pages oftentimes find themselves frustrated with view state, as well. The view state of a page is, by default, placed in a hidden form field named __VIEWSTATE. This hidden form field can easily get very large, on the order of tens of kilobytes. Not only does the __VIEWSTATE form field cause slower downloads, but, whenever the user posts back the Web page, the contents of this hidden form field must be posted back in the HTTP request, thereby lengthening the request time


The load view state stage only happens when the page has been posted back. During this stage, the view state data that had been saved from the previous page visit is loaded and recursively populated into the control hierarchy of the Page. It is during this stage that the view state is validated. As we'll discuss later in this article, the view state can become invalid due to a number of reasons, such as view state tampering, and injecting dynamic controls into the middle of the control hierarchy.


 site has been written in asp.net and as such has a hidden input field with the id "__viewstate". As the user goes through the site this string becomes longer and longer and when I look in the page source the most important part, the content, is underneath all this unwanted code.

Saturday, February 25, 2012

Convert currency number to words Indian currency or foreign currency

Step 1. download this class file MultiCurrency.cs

Step 2. Paste To your Project

Step 3.Use this code where you need to convert
           
            MultiCurrency currenc = new MultiCurrency(Criteria.Indian); \\Set here currency type
            string number = "123.45"\\Your amount set here
            string[] ss = number.Split('.');
            if (ss.Length == 1)
            {
                number = number + ".00";
            }
            string[] amount = number.Split('.');
            string AmountInWords = currenc.ConvertToWord(amount[0]);
            string paises;
            AmountInWords = AmountInWords + " Rupees";
            if (int.Parse(amount[1]) == 0)
            {
                amount[1] = "00";
                paises = "";
            }
            else
            {
                paises = currenc.ConvertToWord(amount[1]);
                paises = " And " + paises + " Paises";
            }




        AmountInWords =AmountInWords +paises ;

Friday, February 24, 2012

Set Printer defalut Font, font size, linespacing and letter spacing in JavaScript and ASP.NET


 function getPrint() {
   
        pp = window.open(); //Adding HTML opening tag with <HEAD> … </HEAD> portion
        pp.document.writeln('<HTML><HEAD><title>Issue Voucher</title>');
        pp.document.writeln('<base target="_self"></HEAD>'); //Adding Body Tag
        pp.document.writeln('<body bottomMargin="0"');
        pp.document.writeln('leftMargin="0" topMargin="0" rightMargin="0" >');
        pp.document.writeln('<form>'); //Creating two buttons Print and Close within a HTML table
        pp.document.writeln('<p id="par">');
     
        pp.document.writeln(document.getElementById('<%=DivPrint.ClientID %>').outerHTML);
//Ending Tag of
 </form>, </body> and </HTML>
     
        //Adding form Tag

        pp.document.writeln('</p>');

        for (i = 0; i < pp.document.all.length; i++) {
            pp.document.all[i].style.fontFamily = "Lucida Console,Script";
            pp.document.all[i].style.fontSize = 10;
            pp.document.all[i].style.lineHeight = 1.5;
            pp.document.all[i].style.fontStyle = "normal";
            pp.document.all[i].style.letterSpacing = "5px";
        }

        pp.document.writeln('</form></body></HTML>');

        pp.document.close();
        pp.focus();
        pp.print();
     
    }


where DivPrint is replace with your Print area

Thursday, February 23, 2012

Remove the URL and Date Time on Printed Page

Step 1. Open Internet Explorer File --> Page Setup..


Step 2.Click Page Setup and Empty the Hesder and Footer Options
   

Create Dynamic table C# asp.net


// code for .aspx page
  <asp:Panel  ID="panpage" runat="server">
   
    </asp:Panel>


// code in aspx.cs page


              Table tbl = new Table();
                tbl.Attributes.Add("border", "0");
                tbl.Attributes.Add("border-color", "Green");
                tbl.Attributes.Add("width", "100%");
                tbl.Attributes.Add("cellpadding", "0");
                tbl.Attributes.Add("cellspacing", "0");
                tbl.Attributes.Add("class", "lblbirthday1");

                panpage.Controls.Add(tbl);
                TableRow tr = new TableRow();
                TableCell tc = new TableCell();
                tc.Attributes.Add("width", "100%");
             
                tc.Attributes.Add("align", "Left");
                tc.Attributes.Add("valign", "top");

                Label name = new Label();
                name.Text = "<font color='block'> " + arrStr1.Replace("@", "<br />") + "</font><br/><font                             color='blue'>-----------------------------------</font>";
                tc.Controls.Add(name);

                tr.Cells.Add(tc);
                tbl.Rows.Add(tr);
                panpage.Controls.Add(tbl);