Tuesday, July 10, 2012

Jquery Showing an element


Showing an element by id

The following example demonstrates how you make a hidden <div> element
with an id appear when someone clicks a button on your page:

1.    Create a Web page containing the following code:

<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <title>My Test Page</title>
    <script type="text/javascript" src="js/jquery-1.4.min.js"></script>
    <script type="text/javascript">
        $(':submit').click(function () {
            $('#showme').show();
        });
    </script>
</head>
<body>
    <div id="showme" style="display: none">
        This will appear.</div>
    <input value="Show" type="submit"></body>
</html>

This code contains a <div> element with an id attribute named
showme. This <div> element is set as hidden using the CSS style attribute
set to display:none.

        $(':submit').click(function () {
            $('#showme').show();
        });


The code says, “When the button is clicked, show the element with the
showme id.” This code uses the :submit selector and the click event
to set up the action. The show function, with an id selector, displays the
element with the showme id.

2.     Save the file, and then view it in your browser.

Showing an element with animation

When you show a hidden element, it disappears instantly. As with the hide
function, the show function allows you to make it appear as though the element
is fading in. To add fade in animations when elements are displayed,
follow these steps:
1. Create a Web page containing the following code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <title>My Test Page</title>
    <script type="text/javascript" src="js/jquery-1.4.min.js"></script>
    <script type="text/javascript">
        $(':submit').click(function () {
            $('#slowshow').show(2000);
            $('#fastshow').show(500);
        });
    </script>
</head>
<body>
    <div id="slowshow" style="display: none">
        This will be shown slowly.</div>
    <div id="fastshow" style="display: none">
        This will be shown quickly.</div>
    <input value="Show" type="submit">
</body>
</html>


This code contains two <div> elements and a button.

        $(':submit').click(function () {
            $('#slowshow').show(2000);
            $('#fastshow').show(500);
        });

The code says, “When the button is clicked, show the element with the
slowshow id at a speed of 2000 milliseconds. Show the element with
the fastshow id at a speed of 500 milliseconds.” This code uses the
:submit selector and the click event to set up the action.
2. Save the file, and then view it in your browser.


Refer from Jquery books and google
Thanks..

Jquery Hiding an element


Hiding an element by type with a button
The following example shows you how you make everything inside <div>
elements disappear when a user clicks a button on your page:

1. Create a Web page containing the following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <title>My Test Page</title>
    <script type="text/javascript" src="js/jquery-1.4.min.js"></script>
    <script type="text/javascript">
        $(':submit').click(function () {
            $('div').hide();
        });
    </script>
</head>
<body>
    <div>
        This will be hidden.</div>
    <div>
        This will be hidden.</div>
    <input value="Hide" type="submit">
</body>
</html>

This code contains two <div> elements and a button.
2. Save the file, and then view it in your browser.

3. Click the button.
Everything in both <div> elements is now hidden

Hiding an element by id when clicked
The next example shows you how you make everything inside a <div> element
with an id disappear when someone clicks that <div> element:

1.     Create a Web page containing the following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <title>My Test Page</title>
    <script type="text/javascript" src="js/jquery-1.4.min.js"></script>
    <script type="text/javascript">
        $('#hideme').click(function () {
            $('#hideme').hide();
        });
    </script>
</head>
<body>
    <div id="hideme">
        This will be hidden.</div>
    <div>
        This will not be hidden.</div>
</body>
</html>

This code contains a <div> element with an id attribute named
hideme. Unlike the preceding example, there is no button.

2. Save the file, and then view it in your browser.



Refer from Jquery books and google
Thanks..

Calling Your JavaScript Code after the Page Loaded


Calling Your JavaScript Code after the Page Has Loaded

Sometimes you will want to execute JavaScript code only when the user tries
to leave your page. You might want to do this because you want to bid the
user farewell or remind the user he or she is leaving your site.
Doing this requires two steps:
• Place the code you want to execute after the page has completed
loading into a function.
• Use the onUnload attribute of the body tag to call the function.
This results in code like the following:
<script language="JavaScript">
function functionName() {
Code to execute when the page finishes loading
}
</script>
</head>
<body onUnload="functionName();">
Body of the page
</body>

</head>
<body>
The following task creates a function that displays a goodbye message in a dialog
box and then only invokes that function when the user leaves the page:
1. Open a new HTML document in your preferred HTML or text editor.
2. Create the header of the document with opening and closing head tags.
3. Insert a script block in the header of the document.
4. Create a function named bye that takes no arguments:
function bye() {
}

5. In the function, use the window.alert method to display an alert
dialog box:
window.alert(“Farewell”);
6. Create the body of the document with opening and closing body tags.
7. In the body tag, use the onUnload attribute to call the bye function:
<body onUnload=”bye();”>
8. In the body of the page, place any HTML or text that you want in
the page so that the final page looks like Listing below code
<head>
<head>
<script language="JavaScript">
<!--
function bye() {
window.alert(“Farewell”);
}
// -->
</script>
</head>
<body onUnload="bye();">
The page’s content.
</body>

Using onUnload to call a function after the user leaves a page.
9. Save the file.
10. Open the file in a browser, and you should see the page’s content.
Navigate to another site and you should see the farewell dialog box.

Friday, July 6, 2012

Exception Handling


An exception is an error that occurs at runtime. Using C#’s exception handling subsystem, you can, in a structured and controlled manner, handle runtime errors. C#’s approach to exception handling is a blend of and improvement on the exception handling mechanisms used by C++ and Java. Thus, it will be familiar territory to readers with a background in either of these languages. What makes C#’s exception handling unique, however, is its clean, straightforward implementation.

A principal advantage of exception handling is that it automates much of the error-handling code that previously had to be entered “by hand” into any large program. For example, in a computer language without exception handling, error codes must be returned when a method fails, and these values must be checked manually, each time the method is called. This approach is both tedious and error-prone. Exception handling streamlines error-handling by allowing your program to define a block of code, called an exception handler, that is executed automatically when an error occurs. It is not necessary to manually check the success or failure of each specific operation or method call. If an error occurs, it will be processed by the exception handler.

Another reason that exception handling is important is that C# defines standard exceptions for common program errors, such as divide-by-zero or index-out-of-range. To respond to these errors, your program must watch for and handle these exceptions.
In the final analysis, to be a successful C# programmer means that you are fully capable of navigating C#’s exception handling subsystem.

Refer from C# books....