-->

Friday, December 5, 2014

Adding Animation to Web Page: jQuery Effects

JQuery library have all the effects for adding animation user can imagine/think about like to animate, fade, toggle, show, hide and etc. All these animation have their own functions according to their job.

jQuery methods allow users to easily use these effects with minimum configuration. In other context we can show or hide any element on the page by using these effects to make better UI. These animation can be done in any event of an existing element. I have listed some of these methods including a brief description:

  • hide(): will hide the related element.
  • show(): will show related element.
  • toggle(): show of hide related element. (If element is shown then it will hide)
  • slideDown()/slideUp(): show or hide related element with sliding motion.
  • slideToggle(): show of hide related element with sliding motion.
  • animate(): this method is used for custom animation.

These methods have also some parameter to be used with e.g. speed (represents predefined speed among slow, normal and fast) and callback (optional - represent a function to be executed after animation completion). Whether the parameter is required or optional is function dependent, may be change in other definition.

$(“#button”).hide(1000); will hide the button as per the given speed
$(“#button”).show(1000); will show the button as per the given speed

Consider following code:

$(".divEmployee").toggle('slow', function(){
             $(".txtMessage").text(successfully done');
          });

It will show/hide the whole div tag and after completion given message will show on the element provided. Following are some examples about how to use these animation methods. Write these according to element on you page and look out the effects.

$(".divEmployee").slideDown('slow');
$(".divEmployee").slideUp('slow');
$(".divEmployee").slideToggle('slow');

The custom animation animate() method will require all the specified parameters to complete the animation. Lookout the following example of custom animation:

  $( "#divEmployee" ).animate({
    opacity: .25,
    height: "toggle"
  }, 4500, function() {
  });

Run this jQuery code and check the animation, don’t forget to confirm the element id on your page. This code will shrinks the height of div to hide it. We will learn more about these effects and how this can stop by using jQuery function.

Program to check for leap year in C

Before writing the program let us see "What is a leap year?"
Definition: A year which satisfies one of the following two cases:

  • It is divisible by 4 and should not be divisibly by 100 
  • Divisible by 400
If one of the condition is true, it is a leap year. But, if both condition are false, the year is not a leap year. The following table shows whether a year is a leap year or not along with the reasons:

Leap year Table

The partial code for this can be written as follows:

if(year % 4 == 0 && year % 100 !=0) || (year % 400 == 0)
printf ("%d is a leap year \n",year);
else
printf("%d is not a leap year \n");

The complete program is shown below:

Program
#include<stdio.h>
void main( )
{
int year;
printf("Enter the year");
scanf("%d",&year);
if((year %4==0 && year %100!=0 ) !! (year %400 == 0))
printf("%d is a leap year ",year);
else
printf("%d is not a leap year",year);
}

Thursday, December 4, 2014

HTML applet tag and their attributes

Applet is a tag in html that is used to create an applet window or applet in an html document.
  Example
<!DOCTYPE html>
<html>
<head>
<title>HTML applet Tags and their attributes</title>
</head>
<body>
<applet code="classname.class" width="300" height="200">
</applet>
</body>
</html>

  Applet tag has following attributes

  Code : This attribute takes the class name of the applet code that is to be displayed . Class is the compiled code for applet
  e.g.   <applet code="abc.class" width="200" height="200" />

  Height : This attribute takes values in pixels to define the height of the applet.

  Width : This attribute takes values in pixels to define the width of the applet.

  Vspace : This attribute takes values in pixels to specify how much space is to be left above and below the object.

  Hspace : This attribute takes values in pixels to specify how much space is to be left to the right and left of the object.

  Align  : This attribute is used to align the object in the applet.

  Title : This attribute takes a string in input which is a title name or short information about the applet. This information is shown as a tooltip which pops when the move is brought over the applet.


Example
<!DOCTYPE html>
<html>
<head>
<title>Example of Line in the applet</title>
</head>
<body>
<applet code="designline.class" width="300" height="200">
</applet>
</body>
</html>

Here is the designline.java file:
import java.applet.*;
import java.awt.*;

public class designline extends Applet
{
 public void paint (Graphics gh)
   {
      gh.drawLine(10,10,200,200);
   }
}

How to retrieve images from database table in ASP.NET

Database is a storage system, through which we can store data permanently into the secondary storage device. Similar to programming languages, database also take some data types for categorize data. like int, Text, DateTime etc. Now, we will discussed on image. In this example we will retrieve images from database. First we store images into database, actually images is not stored directly, so for that path of the images is stored into the database. Now, bind the GridView with the image field.  

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
 
    </div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" Width="280px">
            <Columns>
                <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
                <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
                <asp:ImageField DataImageUrlField="imagepath" HeaderText="Image">
                    <ControlStyle Height="200px" Width="200px" />
                </asp:ImageField>
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [imagetable]"></asp:SqlDataSource>
    </form>
</body>
</html>
Code Generate the following output

How to retrieve images from database table in ASP.NET

Monday, December 1, 2014

Program to find the larger of two numbers using ternary operator

larger = (a>b)? a:b;
The simple logic behind the program is, when a(variable) is greater than b, the value of a is assigned to larger(variable). Otherwise, the value of b is assigned to larger. The program to find the larger of two numbers using ternary operator is shown below:
#include<conio.h>
#include<stdio.h>
void main()
{
int a,b,larger;
clrscr();
printf("Enter a and b:\n");
scanf("%d%d",&a,&b);
/*The larger of a and b is stored in larger*/
larger=(a>b)?a:b;
printf("Larger=%d\n",larger);
getch();
}

Code generate the Following output


Program to find the larger of two numbers using ternary operator

Debugging C program

Debugging is the process of isolating and correcting the errors. One simple method of debugging is to place printf( ) statements throughout the program to display the values of variables. It displays the dynamics of a C program and allows the programmer to examine and compare the data at various points. Once the location of an error is identified and corrected, the debugging statements should be removed. We can use the conditional compilation statements to switch on or off the debugging statements.

Another approach is to use the process of deduction. Here, we arrive at the errors, using the process of elimination and refinement. This is done using a list of possible causes of the error.
The third error-locating method is to backtrack the incorrect results through the logic of the program until the mistake are located. The program is traced backward until the error is located.

How to create aspx page at run time in ASP.NET

ASPX stands for active server page extension. We know that visual studio create a aspx page for dynamic application. Also one another page is created for business logics. If you want to create both pages(presentation+business logic) through code file then first to create two array for both pages. After that save the file through file handling in same solution.

Source Code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
 

</head>
<body>
    <form id="form1" runat="server">
      Enter page Name  <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

        <br />
        <br />
        <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Created Page" />

    </form>
 
     

</body>
</html>

Code Behind file

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      
    }



    protected void Button1_Click(object sender, EventArgs e)
    {

        String[] sourcecode ={"<%@ Page Language=\"C#\" AutoEventWireup=\"true\" CodeFile=\""+  TextBox1.Text.Trim()+".aspx.cs\" Inherits=\""+ TextBox1.Text.Trim()+"\" %>",
                                 "<html xmlns=\"http://www.w3.org/1999/xhtml\">",
                                 "<head runat=\"server\">",
                                 "<title></title>",
                                " </head>",
"<body>",
    "<form id=\"form1\" runat=\"server\">",
    "</form>",
    "</body>",
"</html>"
                             };

        String[] codefile = {
                                "using System;",
"using System.Collections.Generic;",
"using System.IO;",
"using System.Linq;",
"using System.Web;",
"using System.Web.UI;",
"using System.Web.UI.WebControls;",

"public partial class "+ TextBox1.Text.Trim()+" : System.Web.UI.Page",
"{",
    "protected void Page_Load(object sender, EventArgs e)",
    "{",
      
    "}",
    "}"};

        File.WriteAllLines(Server.MapPath("" + TextBox1.Text.Trim() + ".aspx"), sourcecode);
        File.WriteAllLines(Server.MapPath("" + TextBox1.Text.Trim() + ".aspx.cs"), codefile);
        Response.Write("Page Created");

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/" + TextBox1.Text);
    }
}

Code generate the following output

© Copyright 2013 Computer Programming | All Right Reserved