Tuesday, August 31, 2010

Validating form input using JavaScript

Forms are widely used on the Internet. The form input is often being sent back to the server. But how can you be certain that a valid input was done by the user? With the help of JavaScript the form input can easily be checked before sending it over the Internet.

Here it goes Firstle lets not give chance to enter empty fields.

Validation for Blank fields

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>

<script type="text/javascript">
function Verify(){
if(document.getElementById('uidTextBox').value.length==0)
alert("UserId can't be blank");
else if(document.getElementById('pwdTextBox').value.length==0)
alert("Password can't be blank");
else
{
alert("successfully logged in");
window.open("http://www.cooltuts.com/");
}
}
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<p><asp:TextBox ID="uidTextBox" runat="server" /></p>
<p><asp:TextBox ID="pwdTextBox" runat="server" /></p>
<p><asp:Button ID="btnSubmit" OnClientClick="Verify()" runat="server" Text="Button" /></p>
</div>
</form>
</body>
</html>


Email validation

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>

<script type="text/javascript">
function Verify(){
if(document.getElementById('emailTextBox').value.length==0)
alert("Email can't be blank");
else if((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('emailTextBox').value))==false)
alert("Email Not in Correct Format");
else
{
alert("successfully logged in");
window.open("http://www.cooltuts.com/");
}
}
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<p><asp:TextBox ID="emailTextBox" runat="server" /></p>
<p><asp:Button ID="btnSubmit" OnClientClick="Verify()" runat="server" Text="Button" /></p>
</div>
</form>
</body>
</html>

Button Server Control

by Emmaneale Mendu, Web Developer

Another common control for your Web forms is a button that can be constructed using the Button server control. Buttons are the usual element used to submit forms.

The Button control's OnClick event

protected void Button1_Click(object sender, EventArgs e)
{
//Code Here
}

The Button control is one of the easier controls to use, but there are a couple of properties of which you must be aware: Causesvalidation and CommandName. They are discussed below.

CausesValidation Property

If you have more than one button on your Web page and you are working with the validation server controls, you don't want to fire the validation for each button on the form. Setting the CausesValidation property to False is a way to use a button that will not fire the validation process.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Button Control Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" CommandName="1" runat="server" Text="Button1" />
        <asp:Button ID="Button2" CommandName="2" runat="server" Text="Button2" />
        <asp:Button ID="Button3" CommandName="3" runat="server" Text="Button3" />
    </div>
    </form>
</body>
</html>
The Button Command Event

protected void Button_Command(object sender, CommandEventArgs e)
{
switch (e.CommandName)
{
case "1":
Response.Write("Button 1 is Clicked");
break;
case "2":
Response.Write("Button 2 is Clicked");
break;

default :
Response.Write("Button 3 is Clicked");
break;
}
}

Buttons That Work with Client-Side JavaScript
Buttons are frequently used for submitting information and causing actions to occur on a Web page.

You can create a page that has a JavaScript event, as well as a server-side event, triggered when the button is clicked, as shown below.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Button Control Example</title>
<script type="text/javascript" language="javascript">
function AlertHello(){
alert('Hello Emmaneale');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" OnClientClick="AlertHello()" runat="server" Text="Button" />
</div>
</form>
</body>
</html>

Label Server Control

by Emmaneale Mendu, Web Developer

The Label Server control is used to display text in the browser. Because this is a server control, you can dynamically alter the text from your server-side code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Label Control Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <p>
            <asp:Label ID="lblUserName" runat="server" Text="UserName"></asp:Label>
            <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox></p>
        <p>
            <asp:Label ID="lblPassWord" runat="server" Text="PassWord"></asp:Label>
            <asp:TextBox ID="txtPassWord" runat="server"></asp:TextBox>
        </p>
        <p style="padding-left: 80px">
            <asp:Button ID="btnSubmit" runat="server" Text="Submit" /></p>
    </div>
    </form>
</body>
</html>


Programmatically providing text to the Label control
Label1.Text = "Hello Emmaneale";

Saturday, August 28, 2010

JavaScript Functions

Functions

We will use functions in most of our JavaScript programs. Therefore I will talk about this important concept already now. Basically functions are a way for bundling several commands together. Let’s write a script which outputs a certain text three times. Consider the following
approach:

<html>
<script language="JavaScript">

<!-- hide

document.write("Welcome to my homepage!<br>");
document.write("This is JavaScript!<br>");

document.write("Welcome to my homepage!<br>");
document.write("This is JavaScript!<br>");

document.write("Welcome to my homepage!<br>");
document.write("This is JavaScript!<br>");

// -->
</script>
</html>

This will write out the text

Welcome to my homepage!
This is JavaScript!

three times. Look at the source code - writing the code three times brings out the right result.
But is this very efficiently? No, we can solve this better. How about this code which does the same:

<html>
<script language="JavaScript">
<!-- hide

function myFunction() {

document.write("Welcome to my homepage!<br>");

document.write("This is JavaScript!<br>");
}

myFunction();
myFunction();
myFunction();

// -->
</script>
</html>

In this script we define a function. This is done through the lines:

function myFunction() {

document.write("Welcome to my homepage!<br>");

document.write("This is JavaScript!<br>");
}

The commands inside the {} belong to the function myFunction(). This means that our two do- cument.write() commands are bundled together and can be executed through a function call. In our example we have three function calls. You can see that we write myFunction() three times

just below the definition of the function. These are the three function calls. This means that the contents of the function is being executed three times. This is a very easy example of a function.
You might wonder why functions are so important. While reading this tutorial you will certainly realize the benefits of functions. Especially variable passing makes our scripts really flexible we will see what this is later on.

Functions can also be used in combination with event-handlers. Please consider this example:

<html>
<head>

<script language="JavaScript">
<!-- hide

function calculation() {

var x= 12;

var y= 5;

var result= x + y;

alert(result);
}

// -->
</script>

</head>
<body>

<form>
<input type="button" value="Calculate" onClick="calculation()">
</form>

</body>
</html>

(The online version lets you test this script immediately)

The button calls the function calculation(). You can see that the function does certain calculations. For this we are using the variables x, y and result. We can define a variable with the keyword var. Variables can be used to store different values -like numbers, text strings etc. The line var result= x + y; tells the browser to create a variable result and store in it the result of x + y (i.e. 5 + 12). After this operation the variable result is 17. The command alert(result) is in this case the same as alert(17). This means we get a popup window with the number 17 in it.

Javascript Events

Events and event handlers are very important for JavaScript programming. Events are mostly caused by user actions. If the user clicks on a button a click-events occurs. If the mousepointer moves across a link a Mouseover-event occurs. There are several different events. we want our JavaScript program to react to certain events. This can be done with the help of event-handlers. A button might create a popup window when clicked. This means the window should pop up as a reaction to a Click-event. The event-handler we need to use is called onClick. This tells the computer what to do if this event occurs. The following code shows an easy example of the event-handler onClick:

<form>
<input type="button" value="click me" onClick="alert('Yo')">
</form>

There are a few new things in this code - so let’s take it step by step. You can see that we create a form with a button (this is basically a HTML-problem so I won’t cover it here). The new part is onClick="alert(’Yo’)" inside the <input> tag. As we already said this defines what happens when the button is pushed. So if a Click-event occurs the computer shall execute alert(’Yo’).
This is JavaScript-code (Please note that we do not use the <script> tag in this case). alert() lets you create popup windows. Inside the brackets you have to specify a string. In our case this is ’Yo’. This is the text which shall be shown in the popup window. So our script creates a window with the contents ’Yo’ when the user clicks on the button.
One thing might be a little bit confusing: In the document.write() command we used double quotes" and in combination with alert() we use only single quotes ’ -why? Basically you can use both. But in the last example we wrote onClick="alert(’Yo’)" - you can see that we used both double and single quotes. If we wrote onClick="alert("Yo")" the computer would get confused as it isn’t clear which part belongs to the onClick event-handler and which not. So you have to alternate with the quotes in this case. It doesn’t matter in which order you use the quotes - first double quotes and then single quotes or vice versa. This means you can also write onClick=’alert("Yo")’.

There are many different event-handlers you can use. We will get to know some during this tutorial- but not all. So please refer to a reference if you want to know what kind of other event-handlers do exist.

If you are using the Netscape Navigator the popup window will contain the text JavaScript alert. This is a security restriction. You can create a similar popup window with the prompt() method. This window accepts an input. A malicious script could imitate a system message and ask for a certain password. The text in the popup window shows that the window comes from your web browser and not from your operating system. As this is a security restriction you cannot remove this message.

Friday, August 27, 2010

Hiding JavaScript Statements from Older Browsers

Browsers that were distributed before the script tag was invented will correctly ignore tags they do not "understand" such as the script tag. However, the JavaScript statements in between the script tags will appear to these browsers as plain text. Most often older pre JavaScript browsers will therefore render the JavaScript statements as paragraph text. This can be quite alarming if a nicely designed page suddenly appears to someone as a long stream of meaningless code.

To get around this, the code can be hidden inside an HTML comment tag. An HTML comment tag looks like this:

<--This is a comment.-->

The opening <-- part of the tag is usually placed on the next line right after the opening <SCRIPT> tag and the closing part of the comment tag on the line just before the closing </SCRIPT> tag. Just to make things more complicated the closing part of the HTML comment tag must be preceded by the // characters that precede a JavaScript comment. Here is a short example:

<SCRIPT Language="JavaScript">
<!--


// -->
</SCRIPT>

JavaScript statements are placed on the line after the <!-- and on lines before the // -->


Getting Started with Visual Studio

About visual studio .Net integrated development environment:
When we are installing 3.5 .Net framework Automatically getting visual studio 2008 version environment, Using this IDE we can implement all .Net tech, the microsoft given by default only three language features.

1) Visual c#
2) Visual Basic
3) Visual C++

Open visual Studio .Net

Click on Start menu --> programs --> microsoft visual studio 2008 -->Click

environment with start page

Start page having six recently opened projects.

Opening with form Application


Click on the file menu, select new --> click on new project

Getting new project window with two sub windows
i) project types window
ii) templates window

Project types window
It is having collection of .net languages select visual C# in the project types window

Templates window
This window having collection of selected language concepts, select win-forms application from the templates window.

Click OK, getting C#.Net windows application

In the windows form application getting pre-defined container called form, form container having collection of graphical user interface. As per .net framework all containers are classes.

In the form container we can add collection of controls, As per .net framework all controls are objects.

C#.Net Features

Supports OOP Rules .Net technologies are implemented based on object oriented programing rules, In C#.Net rules we can implement data encapsulation, data abstraction, inheritance and polymorphism.

Console Application:
These are used to implement character user interface features, console application output getting in the dos prompt by default.

Windows Application:
Using windows application we can implement graphical user interface features, In the windows application getting pre-define container called form, form-container having collection of controlls.

Graphical designing interface(GDI)
Windows application by default depending on the graphical user interface features, using GUI features we can add the control, we can use the menu's, status box and etc., Using GDI without using any control we can give 2D graphics and 3D graphics in the Form Container.

Type Security
C#.Net language supports type security, In the C#.Net we have to convert all data type values manually, because of the type security in the C#.Net each and every statement is secured.

Structured exception handling
When the application having run-time errors the normal application execution terminates abnormally, to overcome this problem we have to work with exception handling.

Thursday, August 26, 2010

Manage code and Unmanaged code

Managed Code:
It is getting from the .Net technologies, managed code we can classify into two types.
(i) Safe Code  (ii) Unsafe Code

Safe Code:
Getting from .Net technology, Unsafe code supports only functions.

Unsafe Code:
Getting from .Net technology, Unsafe code implemented using pointers.

Unmanaged code:
Getting from different languages, which language giving dynamic link libraries that language features we can access in the .Net framework, It doesnt communicates with the CLR.

The Difference Between HTML and JavaScript

When the browser is reading in a HTML document it needs to be able to determine what text is HTML and therefore what to display in the browser window, and what text is JavaScript source code to be interpreted and executed. One way to let a browser know that part of an HTML document is JavaScript is to enclose it inside the HTML <SCRIPT></SCRIPT> tags as illustrated above. A browser that knows how to interpret Javascript will attempt to interpret text inside the script tags while reading and displaying HTML elements correctly.

Script tags are most often placed inside the head or body tags but may also be placed inside other elements. Not every version of every browser correctly interprets JavaScript code when script tags are placed inside other HTML elements such as table data cells.

JavaScript Statements and Source Code

The JavaScript text is often referred to as "source code" or just "code" and is made up of statements. In the example first javaScript post these two JavaScript statements:

document.write("<P>Script tags can be placed ")
document.write("in the Head of an HTML document.</P>")

write some text, considering of an HTML paragraph, into the Web page being loaded by the browser. The first statement writes the first half of the paragraph and the second writes the last half. A full description of the parts of these statements is provided later but the net effect is to make the text:

<P>Script tags can be placed in the Head of an HTML document.</P>

part of the HTML document.

Wednesday, August 25, 2010

Placing Javascript Statements inside HTML Documents

JavaScript programing statements (source code) made only be placed in certain locations within HTML documents. When a browser with a JavaScript interpreter reads the JavaScript code it can interpret and execute it so that some scripting task is completed. The simple document below shows JavaScript source code placed within HTML <SCRIPT></SCRIPT>

<HTML>
<HEAD>
<TITLE> </TITLE>
<SCRIPT>
document.write("<P>Script tags can be placed ")
document.write("in the Head of an HTML document </P>")
<SCRIPT>
</HEAD>

<BODY>
<H1>The Script Tag: Example 1</H1>
<P>Script tags can also be placed in the Body of an HTML document.</P>

<SCRIPT>
document.write("<P>Script tags will be ignored by ")
document.write("browsers that do not understand them.</P>")
</SCRIPT>

</BODY>
</HTML>

Recently Added Posts in Cool Tuts

  1. Example on ListView Control - ASP.Net
  2. Sample on UserControl - ASP.Net
  3. RadioButtonList Server Control - ASP.Net
  4. RadioButton Server Control - ASP.Net
  5. CheckBoxList Server Control - ASP.Net
  6. CheckBox Server Control - ASP.Net
  7. ListBox Server Control - ASP.Net
  8. HTML doctype - HTML
  9. HTML Bold - HTML
  10. HTML Title - HTML
  11. Out parameters and Reference parameters - C#
  12. Sample Scripts - VBScript
  13. Performance Testing - Performance Testing
  14. Console Namespace - C#
  15. Console Classes - C#
  16. Console Formatting - C#
  17. FSO and Files - VBScript
  18. Types of Performance Testing - Performance Testing
  19. Console Functions - C#
  20. Getting started with console application - C#
  21. FSO and Folders - VBScript
  22. Custom Server Control - ASP
  23. Components of Load Runner - Performance Testing
  24. How to Append Image path to Text File using C# - ASP
  25. DropDownList Server Control - ASP
  26. HyperLink Server Control - ASP
  27. FSO and Drives - VBScript
  28. ImageButton Server Control - ASP
  29. LinkButton Server Control - ASP
  30. Button Server Control - ASP
  31. TextBox Server Control - ASP
  32. Label Server Control - ASP
  33. Load Test Process - Performance Testing
  34. JavaScript Functions - JavaScript
  35. Javascript Event - JavaScript
  36. C#.Net Features - C#
  37. HTML vs JavaScript - HTML
  38. HTML Elements and Attributes - HTML
  39. C# Framework - C#
  40. ASP Virtual Directory - ASP
  41. ASP Protocols - ASP
  42. Managed Code and Unmanaged Code - C#
  43. C# Architecture - C#
  44. Internet Information Services webserver - ASP
  45. Introduction to Javascript - JavaScript

Sunday, August 22, 2010

How to get desired color to controls in .Net

Elements and Attributes

<element_name attribute_name="attribute_value">
                Element Content
</element_name>

1) Elements(aka tags): specify the type of content - how the content will be used in a XML document. XHTML defines its own set of valid element_names (e.g. head, body, h1).

2) Attributes: give special properties to each element. Again, XHTML defines its own set of valid attribute_names (e.g. class, style, id).

Saturday, August 21, 2010

A program consists of two files(class file, csc file)

//csc Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
           Hello Name = new Hello();  //instance Hello class object
           Console.WriteLine("Enter ID 1 or 2");
           Int16 ID = Convert.ToInt16(Console.ReadLine()); //Read the input
           String MyName = Name.FullName(ID); //calling Hello methos
           Console.Write(MyName.ToString()); //Display output
           Console.ReadKey(); //Hold the console application window
          }
      }
}

//Class Hello.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
      class Hello
      {
         public String FullName(Int16 ID)
          {
            if (ID == 1)
               return "Emmaneale";
            else
               return "Mendu";
           }
       }
}

How to display "Hello World" in Console Application

File Hello.cs

Using System; //uses the namespace system

class Hello //file name and class name need not be identical
{
       static void main() //entry point must be called Main
       {
           Console.WriteLine("Hello World"); //Output goes to Console
       }
}

Compile in the Console window(Command prompt)

Output( after Execution)
Hello World

Tuesday, August 17, 2010

Setting Welcome Page in Sharepoint Site

The Welcome Page should be inside the site.

SPSite ositeCollection = new SPSite("http://Servername");
SPWeb oWebsite = ositeCollection.OpenWeb();
SPFolder oFolder = oWebsite.RootFolder;
oFolder.WelcomePage="Shared Documents/Welcome.aspx";
oFolder.Update();
oWebsite.Dispose();

Getting Current User of the Web Application

HttpContext.Current.User.Identity.Name

Sunday, August 15, 2010

How to Copy a Sharepoint site using stsadm

Go to start -> Run

In the Command Prompt Go to

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Bin

Now run the command to Export the sharepoint site

stsadm.exe -o export -url <a href="http://(youroldsite/">http://(youroldsite/</a>) -includeusersecurity -nofilecompression -filename d:\spbackup

Copy the spbackup unto the destination server and run the command to import the site

stsadm.exe -o import -url <a href="https://(yournewsite/">https://(YourNewSite</a>) -includeusersecurity -nofilecompression -filename d:\spbackup

Now the Sharepoint site will be copied to the new location.

Friday, August 6, 2010

HTML Introduction

Welcome to HTML Basics. This Site leads you through the basics of Hyper Text Markup Language.

To begin using HTML, you will need to have a few things. Here is the big list of items you need to have to get started.

1. You will need to have a computer that is running. Most likely you have this already, since you are reading this page.
2. You will need a text editor of your choice. If you have windows, Notepad will do the trick. If you have a Mac, you can use BBE dit. To find Notepad/BBE dit on your computer.

          In Windows 3.x, find the program group named "Accessories" and double click to open it.

3. You will need a web browser of your choice. If you possibly can, use the latest version of Netscape Navigator or Microsoft Internet Explorer.
4. You will need a place to save your work. You can use your hard drive, a floppy disk, or your web server. You don't have to work online, you can write the html and use your web browser offline on your own computer. We will get to that shortly, in the next tutorial.

Okay, once you have the above materials, you can begin creating your own web pages with HTML. Let's move on to the next tutorial, Using the Materials.

JavaScript Introduction

This Post is an introduction to Javascript.

What is JavaScript

Javascript is a new scripting language which is being developed by Netscape. With Javascript you can easily create interactive web-pages. This tutorial shows you what can be done with Javascript - and more importantly how it is done.

Javascript is not Java!

Many people believe that Javascript is the same as Java because of similar names. This is not true though. I think it would go too far at the moment to show you all the differences - so just memorize that Javascript is not Java.

Tuesday, August 3, 2010

C# Architecture

C-language Arch(Dependent):

C-language supports one type of source code, one compiler and one type of binary format data, c-language source code can communicates with the c-compiler, compiler gives object format file, this file having c-language source code in the binary format and information about the operating system, object file can communicates with the one o/s directly. C-language is platform dependent.

Java-language Arch(Independent):

The java language supports one type of source code, one compiler and one type of binary format data, java-language supports java-c compiler this compiler communicates with the java language source code gives class format data. class file having only binary format data doesn't having information about o/s, for executing class file in the various types of operating systems. we have to use java virtual machine(jvm) communicator java lang. is a platform independent.

.Net Arch(Independent):

CSC:
csc is the sub-compiler in the .Net framework, this compiler communicates with the c#.net source code, csc compiler gives intermediate language format file.

Intermediate language format:
IL format having specific language types into the binary format, all IL formats communicates with the common language runtime compiler.

Common Type System(CTS):
Using cts we can convert different language data types into the common type, different data types having in the sub-compilers, common data types having in the CLR.

Common language Specification:
Using CLS we can convert different languages source code into the common source code, different languages source code having in the sub-compilers. common source code having in the CLR.

MSIL:
The MSIL format getting after communicating all sub-compilers with the CLR, MSIL having common type of data typesand source code, MSIL format can communicates with the various operating systems.

Just intime compiler:
JIT compiler is communicator between MSIL format and specific o/s, because of the JIT compilers the .Net technologies are platform independent.