Thursday, September 30, 2010

Image Server Control

If you like photo shooting this control is very important in your life, to show your photos to your friends on a web page you can use ASP Image control. It’s a simple server control where you can display your images on your Web page from the server-side code.

A typical Image control is constructed on web page as shown below.

<asp:Image ID="Image1" Width="300px" Height="300px" ImageUrl="~/Images/CoolTuts.JPG"
runat="server" />

ImageUrl is very important property in our Image Server Control. In this property I am taking a image(CoolTuts.JPG) from Images folder.

Basic Image Control Example




In the above figure I used Image Controls to display three same images with different sizes. If you want to try this just refer to below .aspx source code.

.aspx

<table width="450px">
<tr>
<td rowspan="2">
<asp:Image ID="Image1" Width="300px" ImageUrl="~/Images/CoolTuts.JPG" runat="server" />
</td>
<td>
<asp:Image ID="Image2" Width="150px" ImageUrl="~/Images/CoolTuts.JPG" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Image ID="Image3" Width="150px" ImageUrl="~/Images/CoolTuts.JPG" runat="server" />
</td>
</tr>
</table>

Its pretty easy right?

Lets work on another example using different images on one Image Control.







As you see above three Images I am using one image control and three button controls. When the user clicks on “Cooltuts Image” Image control changes to CoolTuts Image and same way other two buttons PleaseWait and Submit buttons too.

Code and functionality looks as shown below.
.aspx

<form id="form1" runat="server">
<div>
<asp:Image ID="imgMain" Width="300px" ImageUrl="~/Images/CoolTuts.JPG" runat="server" />
<br />
<asp:Button ID="btnCoolTuts" runat="server" Text="CoolTuts Image" BackColor="White" OnClick="btnCoolTuts_Click" />
<br />
<asp:Button ID="btnPleaseWait" runat="server" BackColor="White" Text="PleaseWait Image" OnClick="btnPleaseWait_Click" />
<br />
<asp:Button ID="btnSubmit" runat="server" BackColor="White" Text="Submit Image" OnClick="btnSubmit_Click" />
</div>
</form>


.cs

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

}

protected void btnCoolTuts_Click(object sender, EventArgs e)
{
ReplaceImage(1);
}

protected void btnPleaseWait_Click(object sender, EventArgs e)
{
ReplaceImage(2);
}

protected void btnSubmit_Click(object sender, EventArgs e)
{
ReplaceImage(3);
}

/// <summary>
/// Replace Images According to the Button Clicks
/// </summary>
/// <param name="Number"></param>
private void ReplaceImage(int Number)
{
if (Number == 1)
{
imgMain.ImageUrl = "~/Images/CoolTuts.JPG";
ResetColor();
btnCoolTuts.BackColor = Color.Blue;
btnCoolTuts.ForeColor = Color.White;
}
else if (Number == 2)
{
imgMain.ImageUrl = "~/Images/PleaseWait.JPG";
ResetColor();
btnPleaseWait.BackColor = Color.Blue;
btnPleaseWait.ForeColor = Color.White;
}
else
{
imgMain.ImageUrl = "~/Images/Submit.JPG";
ResetColor();
btnSubmit.BackColor = Color.Blue;
btnSubmit.ForeColor = Color.White;
}
}

/// <summary>
/// Reset all buttons to Default Colors
/// </summary>
private void ResetColor()
{
btnCoolTuts.BackColor = Color.White;
btnCoolTuts.ForeColor = Color.Black;
btnPleaseWait.BackColor = Color.White;
btnPleaseWait.ForeColor = Color.Black;
btnSubmit.BackColor = Color.White;
btnSubmit.ForeColor = Color.Black;
}
}

I am using three button click events and two other functions. That’s it try this on your computer and let me know if any questions or mistakes by me through comments for this post.

Thanks
Emmaneale Mendu
Web Developer

Wednesday, September 29, 2010

-Get current data using DB2
select current date from sysibm.sysdummy1
select current time from sysibm.sysdummy1

-Get number of days between current day and specified date using DB2
select days(current date) - days(date('1999-22-10')) from sysibm.sysdummy1

Example Video on CheckBoxList Server Control in ASP.Net

Remove letters and symbols from a string using Javascript

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

<!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 Replace()
{
var txt=document.getElementById('txtString').value;
var len=txt.length;
var i=0;
for(i=0;i<len;i++)
{
var num=ascii_value (txt[i])
if(num<48 || num>57)
{
txt=txt.replace(txt[i],"");
len=txt.length;
i--;
}
}
alert(txt);
}
function ascii_value (c)
{
c = c.charAt(0);
var i;
for (i = 0; i < 256; ++ i)
{
var h = i . toString (16);
if (h . length == 1)
h = "0" + h;
h = "%" + h;
h = unescape (h);
if (h == c)
break;
}
return i;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtString" runat="server" />
<asp:Button ID="btnSubmit" runat="server" onclientclick="Replace()" Text="Submit" />
</div>
</form>
</body>
</html>

Creating a User Control in ASP.Net

Hello Friends lets work on User control in this post.

Going through the requirements programmers designed a format of editing a control and using that control in all over the project that is called User Control.

Lets start,

First of all

Create a New Web Site, and right click on the solution file and select Add New Item, then in Add New Item window select Web User Control and specify your desire Name in the Name feild and Click Add button.

Name:: sample

So you see a file with .ascx extension. In that file you see default code as shown below.

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Sample.ascx.cs" Inherits="Sample" %>

So lets start writing some code here. You can add any number of controls. By adding any number of controls you need like .aspx page. I just show simple example how it works.

<p>
Welcome to CoolTuts friends, Number one Tutorial Website on WWW
</p>

Add this after the default code, you can also delete the default code and place this above code.

Just build and open .aspx page in which you want to place the usercontrol.

Here you need to add some code before <html> tag

<%@ Register TagPrefix="SomeTagText" TagName="SomeText" Src="~/Sample.ascx" %>

Here you need to add some code before <html> tag

Adding the line above html tag, then add user control on to the location where you desire.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<SomeTagText:SomeText runat="server" />
</div>
</form>
</body>
</html>

Debug and see your usercontrol on Web.

VBScript - XML Object

Create an XML file
Inner text and Inner xml of XML file
Details of a single node

'Create an XML file
Set oXMLDoc = CreateObject("Microsoft.XMLDOM")
Set oRoot = oXMLDoc.createElement("Employees")
oXMLDoc.appendChild oRoot

Set oRecord = oXMLDoc.createElement("Employee")
oRoot.appendChild oRecord

Set oSSN = oXMLDoc.createElement("SSN")
oSSN.Text = "123456789"
oRecord.appendChild oSSN

Set oName = oXMLDoc.createElement("Name")
oName.Text = "Thanvi"
oRecord.appendChild oName

Set oDOB = oXMLDoc.createElement("DOB")
oDOB.Text = "2009-19-06"
oRecord.appendChild oDOB

Set oSalary = oXMLDoc.createElement("Salary")
oSalary.Text = 1000000
oRecord.appendChild oSalary

Set oIntro = oXMLDoc.createProcessingInstruction("xml","version='1.0'")
oXMLDoc.insertBefore oIntro,oXMLDoc.childNodes(0)
oXMLDoc.Save "C:\Employees.xml"


'Get the Inner text and Inner xml of the XML file
Set oXML = CreateObject("Microsoft.XMLDOM")
oXML.async = "false"
oXML.load("C:\Employees.xml")
msgbox "XML of the file "&oXML.xml
msgbox "Inner text of the xml file "&oXML.text

'Get the details of a single node
Set oXML = CreateObject("Microsoft.XMLDOM")
oXML.async = "false"
oXML.load("C:\Employees.xml")
Set MyNode = oXML.SelectSingleNode("/Employees/Employee/Name")
Msgbox "XML of the single Node "&MyNode.xml
Msgbox "Inner Text of the single Node "&MyNode.text
Msgbox "Type of the Node "&MyNode.nodeType

Tuesday, September 28, 2010

RadioButtonList Server Control

The RadioButtonList control is similar to ChckBoxlist Control there you can select more than one item and here we user can select only one item from the list.

A radioButtonList control is written to the page in the following construction:

Figure Goes here…..

<asp:RadioButtonList ID="rdlNumber" AutoPostBack="true" runat="server"
onselectedindexchanged="rdlNumber_SelectedIndexChanged">
<asp:ListItem Text="One" />
<asp:ListItem Text="Two" />
<asp:ListItem Text="Three" />
<asp:ListItem Text="Four" />
</asp:RadioButtonList>

When we are playing on event handler for RadioButtonList control we need onselectedindexchanged event.

It looks like this

Figure goes here…..

.aspx

<form id="Form1" runat="server">
<div>
<asp:Label ID="lblHeader" ForeColor="Orange" Text="How many Children?" runat="server" />
<asp:RadioButtonList ID="rdlNumber" AutoPostBack="true" runat="server"
onselectedindexchanged="rdlNumber_SelectedIndexChanged">
<asp:ListItem Text="One" />
<asp:ListItem Text="Two" />
<asp:ListItem Text="Three" />
<asp:ListItem Text="Four" />
</asp:RadioButtonList>
<br />
<asp:Label ID="lblMessage" ForeColor="BlueViolet" runat="server" />
</div>
</form>


.cs

protected void rdlNumber_SelectedIndexChanged(object sender, EventArgs e)
{
lblMessage.Text = "You have selected " + rdlNumber.SelectedItem.ToString();
}

Have fun J

RadioButton Server Control

RadioButton Server Control

The RadioButton Server Control functionality is similar to the CheckBox control. But the design goes differently. RadioButton symbol is a round button, where as CheckBox symbol is a square box.

RadioButton control on a page takes the following construction:

Figure goes here…..

.aspx

<asp:RadioButton ID="rdlMale" Text="Male" GroupName="Gender" runat="server" />
<asp:RadioButton ID="rdlFemale" Text="Female" GroupName="Gender" runat="server" />

The user can select Male or Female at once. He cant select both as CheckBox does that. I used GroupName property to do this way.


Coming to the Event handler.


Figure Goes Here……

.aspx

<asp:RadioButton ID="rdlMale" AutoPostBack="true" Text="Male" GroupName="Gender"
runat="server" OnCheckedChanged="rdlMale_CheckedChanged" />
<asp:RadioButton ID="rdlFemale" AutoPostBack="true" Text="Female" OnCheckedChanged="rdlMale_CheckedChanged"
GroupName="Gender" runat="server" />
<br />
<asp:Label ID="lblOutput" runat="server" ></asp:Label>

.cs

protected void rdlMale_CheckedChanged(object sender, EventArgs e)
{
if (rdlMale.Checked)
lblOutput.Text = "Welcome Mr.";
else
lblOutput.Text = "Welcome Mrs.";
}

Working with List View Control in ASP.Net 3.5

by Suresh Ruddarraju, .Net Developer
Working with List View Control in ASP.Net 3.5

Advantages of ListView
1. ListView is lighter than GridView.
2. It just renders what we type in template field.
3. We can either design the template by ourselves or use the existing layout from the ListView.
4. We can sort the ListView, Select, Insert, Update, Delete.
5. If we need Paging, we can integrate it with DataPager.
6. Compatible with any datasource : LinqDataSource, SqlDataSource, etc.
7. It supports grouping.

Some Sample Screen Shots of this post.







.aspx
<asp:UpdatePanel ID="upClaimantSearch" runat="server">
<ContentTemplate>
<div>
<table width="1000px">
<tr>
<td>
<table width="900px">
<tr>
<td style="width: 890px" align="center">
<%-- Data Pager for the ListView Section --%>
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="lvTest" PageSize="2">
<Fields>
<asp:TemplatePagerField>
<PagerTemplate>
<table>
<tr id="PageHeaderRow" runat="server">
<%--display like "Page 1 of 2(4 records)" as the pagesize is 2--%>
<td>
Page
<asp:Label runat="server" ID="CurrentPageLabel" Text="<%# Container.TotalRowCount > 0 ? (Container.StartRowIndex / Container.PageSize) + 1 : 0 %>" />
of
<asp:Label runat="server" ID="TotalPagesLabel" Text="<%# Math.Ceiling ((double)Container.TotalRowCount / Container.PageSize) %>" />
(<asp:Label runat="server" ID="TotalItemsLabel" Text="<%# Container.TotalRowCount%>" />
records)
</td>
<td>
<asp:DropDownList ID="ddlGoTo" AutoPostBack="true" runat="server" Width="100px" OnSelectedIndexChanged="ddlGoTo_SelectedIndexChanged" />
</td>
</tr>
</table>
</PagerTemplate>
</asp:TemplatePagerField>
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<asp:ListView ID="lvTest" runat="server" OnItemCommand="lvTest_ItemCommand" OnSorting="lvTest_Sorting"
OnPagePropertiesChanged="lvTest_PagePropertiesChanged" OnDataBound="lvTest_DataBound">
<%--Design Layout with our own --%>
<LayoutTemplate>
<table width="900px">
<tr style="background-color: Scrollbar">
<td align="center">
<table width="900px">
<tr id="headerRow" runat="server">
<td style="width: 225px">
<asp:LinkButton ID="lnkID" runat="server" CommandName="Sort" CommandArgument="ID"
Text="ID"></asp:LinkButton>
</td>
<td style="width: 225px">
<asp:LinkButton ID="lnkName" runat="server" CommandName="Sort" CommandArgument="Name"
Text="Name"></asp:LinkButton>
</td>
<td style="width: 225px">
<asp:LinkButton ID="lnkNumber" runat="server" CommandName="Sort" CommandArgument="Number"
Text="Number"></asp:LinkButton>
</td>
<td style="width: 225px">
<u>
<asp:Label ID="lnkDetails" runat="server" Text="Details" ForeColor="Blue"></asp:Label></u>
</td>
</tr>
<tr id="itemPlaceholder" runat="server" />
</table>
</td>
</tr>
<tr>
<td align="center">
<asp:DataPager ID="SearchDataPagerRD" runat="server" PageSize="2">
<Fields>
<asp:NumericPagerField ButtonType="Link" ButtonCount="2" NextPageText=">>" PreviousPageText="<<" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<%--Item template Gets or sets the custom content for the data item in ListView--%>
<ItemTemplate>
<table width="900px">
<tr>
<td>
<table width="900px">
<tr>
<td style="width: 225px">
<asp:Label ID="lblID" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ID")%>' />
</td>
<td style="width: 225px">
<asp:Label ID="lblName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Name")%>' />
</td>
<td style="width: 225px">
<asp:Label ID="lblNumber" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Number")%>' />
</td>
<td style="width: 225px">
<asp:ImageButton ID="btnReview" runat="server" CommandName="Review" ImageUrl="~/Images/Review.JPG"
CommandArgument='<%# DataBinder.Eval(Container, "DataItem.ID") %>' />
</td>
</tr>
</table>
</td>
</tr>
</table>
</ItemTemplate>
</asp:ListView>
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>

.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class ListViewEx : System.Web.UI.Page
{
//Create a test dataset property
public DataSet TestDataSet
{
get
{
DataSet ds = new DataSet();
DataTable dt = ds.Tables.Add("Details");
dt.Columns.Add("ID", typeof(Int32));
dt.Columns.Add("Name", typeof(String));
dt.Columns.Add("Number", typeof(Int32));

dt.Rows.Add(1, "Abc", 1001);
dt.Rows.Add(2, "Def", 1002);
dt.Rows.Add(3, "Ghi", 1003);
dt.Rows.Add(4, "Xyz", 1004);
return ds;
}
set
{
TestDataSet = value;
}
}

public SortDirection LVSortDirection
{
get
{
if (Session["LVSortDirection"] == null)
{
Session["LVSortDirection"] = SortDirection.Ascending;
}
return (SortDirection)Session["LVSortDirection"];
}

set { Session["LVSortDirection"] = value; }
}

public Int32 LVSearchPageIndex
{
get { return (Int32)Session["LVSearchPageIndex"]; }
set { Session["LVSearchPageIndex"] = value; }
}

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lvTest.DataSource = TestDataSet.Tables[0];
lvTest.DataBind();
}
}

//When we click on review button....
protected void lvTest_ItemCommand(object sender, ListViewCommandEventArgs e)
{
if (e.CommandName == "Review")
{
String SelectedItem = (e.CommandArgument.ToString());

String formatExp = "ID='{0}'";

DataRow[] drRows = TestDataSet.Tables[0].Select(String.Format(formatExp, SelectedItem));
string name = String.Empty;
Int32 Number = 0;
if (drRows.Length > 0)
{
foreach (DataRow dr in drRows)
{
name = dr["Name"].ToString();
Number = Convert.ToInt32(dr["Number"]);
}
}
//passing the name and number in sessions to display in next page
Session["Name"] = name.ToString();
Session["Number"] = Number;

Response.Redirect("Default.aspx");
}
}

protected void lvTest_Sorting(object sender, ListViewSortEventArgs e)
{
String direction = String.Empty;
Image directionimg = new Image();

//If sort direction is Asc,change it to desc(as you clicked for sorting)
if (LVSortDirection == SortDirection.Ascending)
{
LVSortDirection = SortDirection.Descending;
direction = "Desc";
directionimg.ImageUrl = "~/Images/SortDownArrow.gif";
}
else
{
LVSortDirection = SortDirection.Ascending;
direction = "Asc";
directionimg.ImageUrl = "~/Images/SortUpArrow.gif";
}

Session["LVSortExpression"] = e.SortExpression;

SetListSortImage(e.SortExpression, directionimg);

SortListView(e.SortExpression, direction);
}

protected void lvTest_PagePropertiesChanged(object sender, EventArgs e)
{
String sortExpression = String.Empty;
Image image = new Image();
String direction = String.Empty;

if (Session["LVSortExpression"] != null)
{
sortExpression = (String)Session["LVSortExpression"];

if (LVSortDirection == SortDirection.Ascending)
{
image.ImageUrl = "~/Images/SortUpArrow.gif";
direction = "Asc";
}
else
{
image.ImageUrl = "~/Images/SortDownArrow.gif";
direction = "Desc";
}

/// Showing Image in ListView Header
SetListSortImage(sortExpression, image);
SortListView(sortExpression, direction);
}
else
{
lvTest.DataSource = TestDataSet;
lvTest.DataBind();
}

Int32 currentPage = (DataPager1.StartRowIndex / DataPager1.PageSize) + 1;
LVSearchPageIndex = currentPage;
}

protected void lvTest_DataBound(object sender, EventArgs e)
{
//Checking for current page
Int32 currentPage = (DataPager1.StartRowIndex / DataPager1.PageSize) + 1;

DropDownList ddlGo = DataPager1.Controls[0].FindControl("ddlGoTo") as DropDownList;

if (DataPager1.TotalRowCount <= DataPager1.PageSize)
{
ddlGo.Visible = false;
}
else
{
//get total number of pages based on total rows count and page size
Int32 totalPages = Convert.ToInt32(Math.Ceiling((Double)DataPager1.TotalRowCount / DataPager1.PageSize));
ddlGo.Items.Clear();
for (Int16 i = 1; i <= totalPages; i++)
{
//bind page numbers automatically to the dropdownlist
ddlGo.Items.Add(i.ToString());
}
ddlGo.SelectedValue = currentPage.ToString();
}
}


protected void ddlGoTo_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList pageno_ddl = sender as DropDownList;
Int32 PageNo = Convert.ToInt32(pageno_ddl.SelectedValue);
Int32 startRowIndex = (PageNo - 1) * DataPager1.PageSize;
DataPager1.SetPageProperties(startRowIndex, DataPager1.PageSize, true);

}

private void SetListSortImage(String sortExpression, Image imgsortArrow)
{
Literal Space = new Literal();
Space.Text = " ";
//Find all the header rows of listview(headerRow is the tr tag id)
Control headerRow = lvTest.FindControl("headerRow");

foreach (HtmlControl sortCell in headerRow.Controls.Cast<HtmlControl>())
{
//Checks all the header link buttons of listview and compares with sortexpression(Clicked item)
LinkButton btnSortField = sortCell.Controls.OfType<IButtonControl>().SingleOrDefault() as LinkButton;
if (btnSortField != null)
{
if (btnSortField.CommandArgument == sortExpression)
{
var imgControl = sortCell.Controls.OfType<WebControl>().Last();

if (imgControl.GetType().FullName != typeof(Image).FullName)
{
//To Provide space between Header linkbuttonText and ImageArrow
sortCell.Controls.Add(Space);

//add the image
sortCell.Controls.Add(imgsortArrow);
}
}
}
}
}

private void SortListView(String SortExpression, String Direction)
{
DataView dv = null;
//Add the datatable to dataview
dv = new DataView(TestDataSet.Tables[0]);

// provide sortExpression space Direction(Desc or Asc)
dv.Sort = SortExpression + " " + Direction;

//Bind the sorted dataview to listview
lvTest.DataSource = dv;
lvTest.DataBind();
}

}

CheckBoxList Server Control

CheckBoxList Server Control

The CheckBoxList is almost similar to the CheckBox, except user can select more than one option in CheckBoxList. We can work on collection of items rather than using a single item.

CheckBoxList will have a collection of related items. Example shown below,

Like Movies, Cars, Bikes etc.

Adding items in source file.


Image comes here……


Source code….

<asp:Label ID="lblMovies" runat="server" Text="Movies:" Font-Bold="true" />
<asp:CheckBoxList ID="chklMovies" ForeColor="OrangeRed" runat="server">
<asp:ListItem Text="Titanic" Value="1" />
<asp:ListItem Text="Cops Out" Value="2" />
<asp:ListItem Text="Iron Man" Value="3" />
<asp:ListItem Text="3 Idiots" Value="4" />
</asp:CheckBoxList>
<asp:Label ID="lblCars" runat="server" Text="Cars:" Font-Bold="true" />
<asp:CheckBoxList ID="chklCars" ForeColor="OrangeRed" runat="server">
<asp:ListItem Text="Honda" />
<asp:ListItem Text="Acura" />
<asp:ListItem Text="BMW" />
<asp:ListItem Text="Toyota" />
</asp:CheckBoxList>
<asp:Label ID="lblBikes" runat="server" Text="Bikes:" Font-Bold="true" />
<asp:CheckBoxList ID="chklBikes" ForeColor="OrangeRed" runat="server">
<asp:ListItem Text="Hero Honda" />
<asp:ListItem Text="Baja" />
<asp:ListItem Text="TVS" />
<asp:ListItem Text="Honda" />
</asp:CheckBoxList>

Adding items in .cs

Image comes here…..

.aspx code….
<asp:Label ID="lblMovies" runat="server" Text="Movies:" Font-Bold="true" />
<asp:CheckBoxList ID="chklMovies" ForeColor="OrangeRed" runat="server" />
<asp:Label ID="lblCars" runat="server" Text="Cars:" Font-Bold="true" />
<asp:CheckBoxList ID="chklCars" ForeColor="OrangeRed" runat="server" />
<asp:Label ID="lblBikes" runat="server" Text="Bikes:" Font-Bold="true" />
<asp:CheckBoxList ID="chklBikes" ForeColor="OrangeRed" runat="server" />


.cs code….

chklMovies.Items.Add("Titanic");
chklMovies.Items.Add("Cops Out");
chklMovies.Items.Add("Iron Man");
chklMovies.Items.Add("3 Idiots");

chklCars.Items.Add("Honda");
chklCars.Items.Add("Acura");
chklCars.Items.Add("BMW");
chklCars.Items.Add("Toyota");

chklBikes.Items.Add("Hero Honda");
chklBikes.Items.Add("Baja");
chklBikes.Items.Add("TVS");
chklBikes.Items.Add("Honda");


Examples on how to handle events usinf Autopostback property.

.aspx

<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
<asp:Label ID="lblMovies" Text="Select your Favorate movie:<br/>" runat="server"
Font-Bold="true" />
<asp:CheckBoxList AutoPostBack="true" ID="chklMovies" ForeColor="Violet" runat="server"
OnSelectedIndexChanged="chklMovies_SelectedIndexChanged">
<asp:ListItem Text="Titanic" />
<asp:ListItem Text="Cops Out" />
<asp:ListItem Text="Iron Man" />
<asp:ListItem Text="3 Idiots" />
</asp:CheckBoxList>
<asp:Label ID="lbloutput" runat="server" Font-Bold="true" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>

.cs

protected void chklMovies_SelectedIndexChanged(object sender, EventArgs e)
{

Int16 flag = 0;
String str=String.Empty;
Int16 i = 1;
foreach (ListItem item in chklMovies.Items)
{
if (item.Selected == true)
{
str +=i+") "+ item.Text + "<br/>";
flag = 1;
i++;
}
}

if (flag == 0)
{
lbloutput.Text = "Select atleast one movie";
lbloutput.ForeColor = Color.Red;
}
else
{
lbloutput.Text = "You selected " + (i-1) + " Movies<br/>"+str;
lbloutput.ForeColor = Color.Black;
}
}

Copy, paste and execute. Let me know if any questions through commenting on this article

Friday, September 24, 2010

HTML doctype

HTML doctype

The <!DOCTYPE ...> declaration (technically it's not a "tag") should be the very first thing in your document. A DOCTYPE is required to validate the document.

The version of HTML against which the document is validated is based on the DOCTYPE.

Different version doctype is shown below.

This is the <!DOCTYPE ...> declaration

For HTML version 3.2:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

For HTML version 4.0: we have three standard doctypes.
The documents that strictly confirm and that aren’t frameset documents use this
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd”>

For a not quite so strict conformance use this
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">

For documents which are frameset documents use this
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN"
"http://www.w3.org/TR/REC-html40/frameset.dtd">

HTML Bold

The HTML bold tag is used for specifying bold text

<html>
<head>
<title>Cooltuts.com</title>
</head>
<body>

Hello Friends <b>I am bold</b> Welcome

</body>
</html>

Few attributes you can use in this bold tag

Title: some browser displays this text when the user keeps his cursor on this text example as shown below.

<html>
<head>
<title>Cooltuts.com</title>
</head>
<body>

Hello Friends <b title="bold text">I am bold</b> Welcome

</body>
</html>

Like title you can use

class, dir, id, lang, style, onclick, ondbclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup.

Thursday, September 23, 2010

HTML Title

Title is very important to every web page, by reading title user should know what content can expect in that page/screen. As of me the title is supposed to describe the whole page in a few words.

<html>
<head>
<title>Cooltuts.com</title>
</head>
</html>

As you see above example title tag <title> comes in between head tag <head>. This title content appears on your web browser tab or browser title bar – at the very top of the window.

Mainly search engines like Bing, Google takes title as main content and show according to the title. So, your title should contain everything means main keywords. Especially if someone likes your web page and he puts your page to favorites or bookmarks then this title will appear.

Try to search something in Bing/Google then you will see title appears as our link to a particular site.

Out type parameters and Reference type parameters:

The Microsoft newly introduced out parameters in the c#.net, Using out Parameters we can send formal parameter value into the Actual parameter, while working with the out type parameters we have to initialize values to the formal parameters, out type parameters function can returns collection of values.

It’s very hard to get understand the above sentence let me explain you with example.  First I will show you a code which includes a class and view variables.

class Student
    {
        static void Main()
        {
            Number abc = new Number();
            int i=1000;
            abc.Calc(i);
            Console.WriteLine(i);

            Console.Write("Press any key to continue...");
            Console.ReadKey();
        }

        class Number
        {
            public void Calc(int i)
            {
                Console.WriteLine(i);
                i = 2000;
            }
        }
      
    }

OutPut
1000
1000

Here “abc” is an object that looks like “Number” class created. Variable “i” is initialized to a value 100. So using “abc” object we are calling “Calc” method with one parameter. Here i am sending value 100 when I call “Calc” method from Main() and display the value inside the “Calc” method.

Again while going back to Main() i assigned a value to “i=2000” and then WriteLine will display the value 1000 again. By this example if we change the variable name in the method “Calc” it wont effect the variable in Main() method.

So to retrieve this requirement microsoft introduce this concepts.

Here below code explains you first program using out parameter with error.

class Student
    {
        static void Main()
        {
            Number abc = new Number();
            int i=1000;
            abc.Calc(i);
            Console.WriteLine(i);

            Console.Write("Press any key to continue...");
            Console.ReadKey();
        }

        class Number
        {
            public void Calc(out int i)
            {
    Console.WriteLine(i);
                i = 2000;
            }
        }
      
    }

Error
Error 1 The best overloaded method match for 'ConsoleApplication2.Student.Number.Calc(out int)' has some invalid arguments
Error 2 Argument '1' must be passed with the 'out' keyword
Error 3 Use of unassigned out parameter 'i'

The above code is same as our previous one. I just added a “out” keyword in “Calc” function. This “out” keyword indicates what ever the changes made to “i” in “Calc” function that should return to Main(). But here we forgot put “out” keyword in calling function “abc.Calc(i);” so its throwing error. We need to mention “abc.Calc(out i);” to retrieve by this error as shown below code and with little modification.

class Student
    {
        static void Main()
        {
            Number abc = new Number();
            int i=1000;
          
            Console.WriteLine(i);
            abc.Calc(out i);
            Console.WriteLine(i);

            Console.Write("Press any key to continue...");
            Console.ReadKey();
        }

        class Number
        {
            public void Calc(out int i)
            {
                i = 2000;
            }
        }      
    }
OutPut
1000
2000

Hence the variable “i” changed to 2000 Great. But in the previous code I am trying to display in Calc method and that through an error because when you mention “out” in the method parameters then it won’t take “in”. Like try to change “i=2000” to “i=i+2000”. It will through you an error (unassigned).

To retrieve this particular requirement Microsoft introduced Reference type parameters.

Reference type parameters:
Using reference type parameters we can send actual parameters. Address into the formal parameters, In the reference type parameters formal parameters modifications effects in the actual parameters, As per C#.Net we can get the variable address, we can send the variable address. Using “ref” keyword.

This also explained with examples. Let’s change “out” to “ref” in the above program.

class Student
    {
        static void Main()
        {
            Number abc = new Number();
            int i=1000;
          
            Console.WriteLine(i);
            abc.Calc(ref i);
            Console.WriteLine(i);

            Console.Write("Press any key to continue...");
            Console.ReadKey();
        }

        class Number
        {
            public void Calc(ref int i)
            {
                i =2000;
            }
        }      
    }

OutPut
1000
2000

Same as above, But as I told you we are getting an error when I am trying to use “I” in the “Calc” method like “i=i+2000”. Let’s try this using “ref” in the function.

class Student
    {
        static void Main()
        {
            Number abc = new Number();
            int i = 1000;

            Console.WriteLine(i);
            abc.Calc(ref i);
            Console.WriteLine(i);

            Console.Write("Press any key to continue...");
            Console.ReadKey();
        }

        class Number
        {
            public void Calc(ref int i)
            {
                i = i + 2000;
            }
        }
    }

OutPut
1000
3000

Wow, it solved our error.

 Let me show the drawback of “ref” parameter as shown below code.

class Student
    {
        static void Main()
        {
            Number abc = new Number();
            int i;

            abc.Calc(ref i); //Error
            Console.WriteLine(i);

            Console.Write("Press any key to continue...");
            Console.ReadKey();
        }

        class Number
        {
            public void Calc(ref int i)
            {
                i = 1000;
                i = i + 2000;
            }
        }
    }

Error
Error 1 Use of unassigned local variable 'i'

So, by this we came to know while working on ref parameter we need to send value too. But for out parameters there is no use to send value.

Types of Testing

There are two Types of Testing

  1. White box testing: Test Cases are generated based on the source code of the software.
  2. Black box testing: Test Cases are generated based on the functionality of the software

Other types of Testing
1. Unit Testing: We check whether individual units of the source code are working properly or not.
2. Integration Testing
3. Functional Testing
4. Usability Testing : Testing User friendliness, simplicity of the software
5. System Testing
6. Performance Testing
7. Load Testing
8. Security Testing: Testing the access rights of the user
9. Installation Testing: Testing the software while installing it in different environments

Wednesday, September 22, 2010

CoolTuts - Performance Testing - Introduction to Load Runner

Load Runner is a commercial performance and load testing tool for examining how software application behaves while placed under load.

LoadRunner emulates the load generated by any number of users from few to many thousand.

Introduction to WinRunner

While Recording WinRunner stores the Object description in the GUI Map.
WinRunner uses the objecct description in the GUI Map file, and produces the results.

WinRunner uses Mercury Interactive Test Script Language (TSL) for scripting.

How does winrunner identify the objects
Winrunner uses object's physical attributes to identify the object.

How does winrunner uniquely identifies the objects
Winrunner uses the minimum number of attributes to achieve unique identification.

Winrunner identifies the objects within the scope of the parent window.

GUI Map File

GUI Map file contains:
1. Windows of the AUT
2. Objects within each window
3. Physical attributes that create each object's unique identification

Run Modes

1. Debug Mode
2. Verify Mode
3. Update Mode

Recording Modes in WinRunner

1. Context Sensitive Mode
2. Analog Mode

Commands of WinRunner

Statements in Context Sensitive Mode
invoke_application("Notepad","","c:\\temp",SW_SHOW);
set_window("Login",10); Waits for the specified window to appear on screen. If the window appears before the timeout, the script immediately proceeds to the next line.
button_press("OK") ;
button_set("Order","ON")
win_activate
win_exists("Flight Reservations",2)
list_get_num_items
list_select_item("Make","BMW");
edit_set("User ID:","guest");
password_edit_set("password","mxpvnwoulxjxau");
edit_get_text
menu_select_item("File;Openn Order");
GUI_close_all();
GUI_close("");
GUI_load("X:\\guimaps_myguifile.gui");

Synchronization Statement
Object Synchronization Statements
win_wait_info("Payment","enabled",0,30);
obj_wait_info("StatusBar","label","Done",20)

Time Synchronization

wait(10) ; waits for the specified amount of time


Bitmap Synchronization

obj_wait_bitmap("Object","Img1",10)
win_wait_bitmap("Screen","Img2",10, 210, 175, 80, 22)

GUI Checkpoints
Verifies whether object's properties match with the expected results. Checkpoint differs depending on the object to be verified.
For Example:
Single Property check GUI checkpoints
List Box control - list_check_info
Button control (check box, radio button, push button) - button_check_info
Generic Object - Obj_check_info
Window - Win_check_info
Multiple Property check GUI checkpoints
obj_check_gui("progressbar","list1.ck1","gui1",25);
win_check_gui("Report","list1.ck1","gui2",4);

Bitmap Checkpoint statements:
obj_check_bitmap("progressbar","Img1",25);
obj_check_bitmap("statusbar","Img2",25,0,10, 50, 10);
win_check_bitmap("Reports","Img3",4);

Text Checkpoint statements

obj_get_text("Statusbar95",text) ;obj_get_text: retrieves the text within an area

Database Checkpoints

db_check("list1.cd1","dbvf1");

Log Statements

tl_step: lots message in the WinRunner report and changes test status
if (text == "Insert Done...")
tl_step("Check statusbar","Pass","Insert was completed");
else
tl_step("Check statusbar","Fail","Insert Failed");

Statements in Analog Recording Mode
move_locator
move_location_track(1);
move_locator_abs
type("ls\-l");

Analog Synchronization
win_wait_bitmap("Win_1","icon_editor",4, 855, 801, 190, 80);
win_wait_bitmap: waits for a window bitmap to appear onscreen. Bitmap may be full/partial window area. Optionally, bitmap filename may be omitted, thus synchronizing on window refresh/redraw.

Tuesday, September 21, 2010

Disadvantages of Manual Testing

Following are the disadvantages of Manual Testing.
1. Time-consuming and Tedious
2. Requires heavy investment of human resources.
3. It is impossible for a man to test every feature thoroughly before the software is released

Sample Scripts

'Using Integer Array
A(0) = 10
A(1) = 20
A(2) = 30
For i = 0 to 2
msgbox A(i)
Next

'Using String Array
StringArray(0) = "ArrayVariable1"
StringArray(1) = "ArrayVariable2"
StringArray(2) = "ArrayVariable3"
For i = 0 to 2
msgbox StringArray(i)
Next

'Split a string
Dim StringName, SplitString
StringName = "My name is xxx. I studied 10th class. I completed intermediate"
SplitString = split(StringName, " ")
For i = 0 to ubound(SplitString(i))
msgbox SplitString(i)
Next
'or
For i = LBound(SplitString) to UBound(SplitString)
msgbox SplitString(i)
Next

' Gets the Current Date, Current Time
Dim TodaysDate, CurTime, CurDateTime
TodaysDate = Date
CurTime = Time
CurDateTime = Now
msgbox "Today's Date "&TodaysDate
msgbox "Current Time "&CurTime
msgbox "Current Date and Time "&Now

Monday, September 20, 2010

CheckBox Server Control

CheckBox Server Control

CheckBox controls user to check the mandatory or optional checkbox depending on the requirement.

CheckBox code: without AutopostBack property. When there is an option that user should select the Terms and conditions before submitting the form.

.aspx

<form id="form1" runat="server">
<div>
<asp:CheckBox ID="CheckBox1" runat="server" Text="I accept the terms and conditions" />
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>

.cs

protected void Button1_Click(object sender, EventArgs e)
{
if (CheckBox1.Checked)
{
Label1.Text = "CheckBox1 am checked";
}
else
{
Label1.Text = "Please Accept the terms and conditions to Continue";
}
}

CheckBox code: When user selects the checkbox then an event called.

.aspx

<form id="form1" runat="server">
<div>
<asp:CheckBox ID="CheckBox1" AutoPostBack="true" runat="server"
Text="Donate 10$ to CoolTuts" oncheckedchanged="CheckBox1_CheckedChanged" />
<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>

.cs

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox1.Checked)
Label1.Text = "Thanks for your donation";
else
Label1.Text = String.Empty;
}

ListBox Server Control

ListBox Server Control
ListBox control is used same as DropDownList Control. It also displays collection of items. Where as the difference is in DropDown you can select only one item here in the ListBox control you can select One or more items.

ListBox code when user can select single item

<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem>ASP.NET</asp:ListItem>
<asp:ListItem>C#.NET</asp:ListItem>
<asp:ListItem>VB.NET</asp:ListItem>
<asp:ListItem>JAVASCRIPT</asp:ListItem>
</asp:ListBox>

ListBox code when user can select multiple items by using “selectionmode” property. Use Control button on your keyboard to select multiple items

<asp:ListBox ID="ListBox2" runat="server" SelectionMode="Multiple">
<asp:ListItem>ASP.NET</asp:ListItem>
<asp:ListItem>C#.NET</asp:ListItem>
<asp:ListItem>VB.NET</asp:ListItem>
<asp:ListItem>JAVASCRIPT</asp:ListItem>
</asp:ListBox>

Let’s see small example on this ListBox with C# coding.


.aspx

<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<br />
<br />
<asp:ListBox ID="ListBox1" runat="server">
</asp:ListBox>
<br />
<br />
<asp:ListBox ID="ListBox2" runat="server" SelectionMode="Multiple">
<asp:ListItem>ASPNET</asp:ListItem>
<asp:ListItem>C#NET</asp:ListItem>
<asp:ListItem>VBNET</asp:ListItem>
<asp:ListItem>JAVASCRIPT</asp:ListItem>
</asp:ListBox>
<br />
<br />
<asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click" />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>


.cs

protected void Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.Add(TextBox1.Text);
}

protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = "You selected from the ListBox:<br>";
foreach(ListItem li in ListBox2.Items)
{
if (li.Selected)
{
Label1.Text += li + "<br>";
}
}
}


Requirement can be like, if you select listbox item automatically the event should call for this we use AutoPostback=true and SelectedIndexCnaged event as shown below.


.aspx

<asp:ListBox ID="ListBox3" runat="server" SelectionMode="Multiple"
AutoPostBack="true" onselectedindexchanged="ListBox3_SelectedIndexChanged">
<asp:ListItem>ASPNET</asp:ListItem>
<asp:ListItem>C#NET</asp:ListItem>
<asp:ListItem>VBNET</asp:ListItem>
<asp:ListItem>JAVASCRIPT</asp:ListItem>
</asp:ListBox>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
<br />


.cs

protected void ListBox3_SelectedIndexChanged(object sender, EventArgs e)
{
Label2.Text = "You selected from the ListBox:<br>";
foreach (ListItem li in ListBox3.Items)
{
if (li.Selected)
{
Label2.Text += li + "<br>";
}
}
}

HTML Randome topics

  1. How to get HTML link or anchor tag without underline

How to get HTML link or anchor tag without underline

by Emmaneale Mendu, Web Developer
Basic anchor or link code looks like this
<a href="http://www.cooltuts.com/">Visit Cooltuts.com</a>

On Web browser this looks like
Visit Cooltuts.com

Let’s work with style property to remove the Underline to the link; basically if the text is underlined then by default user thinks it’s a link. But in some cases the requirement will be without underline.
We use “text-decoration” to overcome this issue. This is a style property we do have none|inherit|combination of ‘underline’,’overline’,’line-through’ and ‘blink’

Properties

style="text-decoration:none" (remove complete decoration like underline)
style="text-decoration:underline"
style="text-decoration:overline"
style="text-decoration:line-through"
style="text-decoration:blink" (wont work in IE but works in Mozila)

If you are using style="text-decoration:none"

<a href="http://www.cooltuts.com/" style="text-decoration:none">Visit Cooltuts.com</a>

Output looks like
Visit Cooltuts.com

Sunday, September 19, 2010

CoolTuts - Performance Testing - Performance Testing

Definition:
Performance testing determines how fast the System Performs operations under a particular workload in software engineering

Performance testing is just a theoretical concept whereas load and stress testing are practically used in software testing process.

Load testing on application enables developers to isolate bottlenecks in any component of the infrastructure.
Example: Measures application ability to sustain concurrent users while maintaining adequate response time.

Components of Load Testing
Load Balancers
: They take incoming load of the client requests and distribute the load across multiple server resources.
Load Generator: It is a machine which serves as a host for running Vusers.

Arrays in Console Application/C#

Arrays in Console Application/C#
All programming languages come across the concept of arrays. So this is very important. Basically arrays are used to store a group of data which are having same data type. I will few examples of arrays in this post.
class abc
    {
        static void Main()
        {
            int[] array;
            array = new int[3];

            array[0] = 1;
            array[1] = 2;
            array[2] = 3;

            Console.WriteLine(array[0]);
            array[0]++;
            Console.WriteLine(array[0]);
            ++array[1];
            Console.WriteLine(array[1]);

            int i=1;
            Console.WriteLine(array[i]);
            i = 5;
            Console.WriteLine(array[i]); //Error
            Console.ReadKey();
        }
Error:
Index was outside the bounds of the array.
We declare arrays with a set of [] brackets. As our example int[] array means array is like of int[].  And instantiate array with new keyword. Number 3 in the square bracket indicate that the user want to store 3 items or 3 records. Hence in the array the items count/index start at ‘0’ and end at ‘n-1’. As shown in the example it starts at ‘0’ and end at ‘2’. But we are trying to pull the record that is not created so we got this error.


static void Main()
        {
            int[] array;
            array = new int[3];

            array[0] = 1;
            array[1] = 2;
            array[2] = 3;

            Console.WriteLine(array[0]);
            array[0]++;
            Console.WriteLine(array[0]);
            ++array[1];
            Console.WriteLine(array[1]);

            int i=1;
            Console.WriteLine(array[i]);
            i = 2;
            Console.WriteLine(array[i]); //Error
            Console.ReadKey();
        }


OutPut
1
2
3
3
3

Hurry! No errors, It looks we are having more code with similar content lets use loop concept to minimize the code. As shown below

class abc
    {
        static void Main()
        {
            int[] array;
            array = new int[3];
            int i;
            for (i = 0; i < 3; i++)
                array[i] = i + 1;

            for (i = 0; i < 3; i++)
                Console.WriteLine(array[i]);

            Console.ReadKey();
        }
    }

OutPut
1
2
3

Hence we minimized the code and removed all errors. Now we will see how ‘foreach’ works with same code. As shown below.
class abc
    {
        static void Main()
        {
            int[] array;
            array = new int[3];
            int i;
            for (i = 0; i < 3; i++)
                array[i] = i + 1;

            foreach(int p in array)
                Console.WriteLine(p);

            Console.ReadKey();
        }
    }
OuPut
1
2
3

Constructor and Destructor

by Emmaneale Mendu
Constructors:

Constructors are nothing but methods that are called automatically at the time of birth or creation of the object. This should have a name, same to the class name. Let see with an example.


class abc
    {
        static void Main()
        {
            xyz a = new xyz();

            Console.ReadKey();
        }
    }

    class xyz
    {
        public xyz()
        {
            Console.WriteLine("I am Constructor");
        }
    }

OutPut
I am Constructor

Above example you see class 'xyz' as a method with same name that constructor so when an object is created for 'xyz' then xyz() method called automatically. Let’s try this differently as shown below.

class abc
    {
        static void Main()
        {
            xyz a = new xyz();
            a.xyz(); //Error

            Console.ReadKey();
        }
    }

    class xyz
    {
        public xyz()
        {
            Console.WriteLine("I am Constructor");
        }
    }

Error 1 'ConsoleApplication2.xyz' does not contain a definition for 'xyz' and no extension method 'xyz' accepting a first argument of type 'ConsoleApplication2.xyz' could be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\emendu\My Documents\Visual Studio 2008\Projects\ConsoleApplication2\ConsoleApplication2\Program.cs 13 15 ConsoleApplication2

Oops! Error, by seeing we came to know that we cannot call constructor manually. OK

Destructors:

A destructor is also a method/function with the same name as class name like constructor but basic difference is

Constructor = ‘public method_name()’
Destructor = ‘~method_name()’

Explanation wise, a constructor gets called at birth whereas a destructor gets called at death.

Move forward and check example to get brief idea.

class abc
    {
        static void Main()
        {
            xyz a = new xyz();

            Console.ReadKey();
        }
    }

    class xyz
    {
        public xyz()
        {
            Console.WriteLine("I am in Constructor");
        }

        ~xyz()
        {
            Console.WriteLine("I am in Destructor");
        }
    }

OuPut
I am in Contructor
I am in Destructor

Friday, September 17, 2010

CoolTuts - Performance Testing - Load Testing Process

1. Plan the Test: We develop a test plan to ensure that test scenario's will accomplish load-testing objectives.

2. Create Vusers: We create Vuser Scripts that contain

  1. Task performed by each Vuser
  2. Task performed by all the Vusers
  3. Tasks measured as Transactions
3. Creating the Scenario:
Scenario describes events that occur during testing session. Scenarios include
  1. List of machines
  2. Scripts
  3. Vusers that run during the scenario
Scenarios are created using Load Runner Controller.
4. Running the Scenario
5. Monitoring the Scenario
6. Analyzing the Test Results:
We use graphs and reports to analyze the application's performance.

CoolTuts - Performance Testing - Load Runner

Components of Load Runner

1. Virtual User Generator (VuGen): It is used to develop scripts for variety of application types and communication protocols.
Virtual User Script is divided into 3 sections:
  1. Vuser_init: These actions are performed when Vuser is loaded or initialised.
  2. Actions: These actions are performed when Vuser is in "Running" state
  3. Vuser_end: These actions are performed when Vuser finishes or stops.
2. Controller: It is used to manage the test scripts and create scenarios. Scenarios means Scripts, Host Machines and Number of Virtual Users.
3. Analysis: It is used to examine the test Results. It yields a series of graphs and reports that helps summarize and present end-to-end test summary results. We can create cross scenario comparison graphs.
4. Launcher: It provides a single point of access for all load runner components.

Thursday, September 16, 2010

ISTQB Questions

1. What is the strong code coverage tool.
a. Decision Coverage
b. Condition Coverage
c. Statement Coverage
d. Path Coverage
Answer: d

2. Typical defects discovered by static analysis includes
a. Programming standard violations
b. Referring a variable with an undefined value
c. security vulnerabilities
d. All Above
Answer: a

3. System Integration testing should be done after
a. Integration testing
b. System testing
c. unit testing
d. component integration testing
Answer:b

4. Which rule should not be followed for reviews
a. Defects and issues are identified and corrected
b. The product is reviewed not the producer
c. All members of the reviewing team are responsible for the result of the review
d. Each review has a clear predefined objective

5. A tool that supports traceability, recording of incidents or scheduling of tests is called
A. a dynamic analysis tool
B. a test execution tool
C. a debugging tool
D. a test management tool
E. a configuration management tool
Answer:D

6. Poor software characteristics are
A. Only Project risks
B. Only Product risks
C. Project risks and Product risks
D. Project risks or Product risks
Answer:B

7. System testing should investigate
A. Non-functional requirements only not Functional requirements
B. Functional requirements only not non-functional requirements
C. Non-functional requirements and Functional requirements
D. Non-functional requirements or Functional requirements
Answer:C

8. Contract and regulation testing is a part of
A. System testing
B. Acceptance testing
C. Integration testing
D. Smoke testing
Answer:B

9. Find the correct flow of the phases of a formal review
A. Planning, Review meeting, Rework, Kick off
B. Planning, Individual preparation, Kick off, Rework
C. Planning, Review meeting, Rework, Follow up
D. Planning, Individual preparation, Follow up, Kick off
Answer:C

10. Which is not the testing objectives
A. Finding defects
B. Gaining confidence about the level of quality and providing information
C. Preventing defects.
D. Debugging defects
Answer:D

11.Maintenance releases and technical assistance centers are examples of which of the following costs of quality?
A. External failure
B. Internal failure
C. Appraisal
D. Prevention
Answer:A

12. Which is not the project risks
A. Supplier issues
B. Organization factors
C. Technical issues
D. Error-prone software delivered
Answer:D

13. Bug life cycle
A. Open, Assigned, Fixed, Closed
B. Open, Fixed, Assigned, Closed
C. Assigned, Open, Closed, Fixed
D. Assigned, Open, Fixed, Closed
Answer:A

14. Who is responsible for document all the issues, problems and open point that were identified during the review meeting
A. Moderator
B. Scribe
C. Reviewers
D. Author
Answer:B

15. ‘X’ has given a data on a person age, which should be between 1 to 99. Using BVA which is the appropriate one
A. 0,1,2,99
B. 1, 99, 100, 98
C. 0, 1, 99, 100
D. –1, 0, 1, 99
Answer:C

16. Which is not a testing principle
A. Early testing
B. Defect clustering
C. Pesticide paradox
D. Exhaustive testing
Answer:D

17.A project that is in the implementation phase is six weeks behind schedule. The delivery date for the product is four months away. The project is not allowed to slip the delivery date or compromise on the quality standards established for his product. Which of the following actions would bring this project back on schedule?
A. Eliminate some of the requirements that have not yet been implemented.
B. Add more engineers to the project to make up for lost work.
C. Ask the current developers to work overtime until the lost work is recovered.
D. Hire more software quality assurance personnel.
Answer:A

18. The ___________ Testing will be performed by the people at client own
locations
A. Alpha testing
B. Field testing
C. Performance testing
D. System testing
Answer:B

19.Which of the following is the standard for the Software product quality
A. ISO 1926
B. ISO 829
C. ISO 1012
D. ISO 1028
Answer:A

20.Which is not a black box testing technique
A. Equivalence partition
B. Decision tables
C. Transaction diagrams
D. Decision testing
Answer:D

21. Find the mismatch
A. Test data preparation tools – Manipulate Data bases
B. Test design tools – Generate test inputs
C. Requirement management tools – Enables individual tests to be traceable
D. Configuration management tools – Check for consistence
Answer:D

22.Evaluating testability of the requirements and system are a part of which phase:-
A. Test Analysis and Design
B. Test Planning and control
C. Test Implementation and execution
D. Evaluating exit criteria and reporting
Answer:A

23. Which of the following has highest level of independence in which test cases are:
A. Designed by persons who write the software under test
B. Designed by a person from a different section
C. Designed by a person from a different organization
D. Designed by another person
Answer:C

24.Test planning has which of the following major tasks?
i. Determining the scope and risks, and identifying the objectives of testing.
ii. Determining the test approach (techniques,test items, coverage, identifying and
interfacing the teams involved in testing , testware)
iii. Reviewing the Test Basis (such as requirements,architecture,design,interface)
iv. Determining the exit criteria.
A. i,ii,iv are true and iii is false
B. i,,iv are true and ii is false
C. i,ii are true and iii,iv are false
D. ii,iii,iv are true and i is false
Answer:A

25. Deciding How much testing is enough should take into account :-
i. Level of Risk including Technical and Business product and project risk
ii. Project constraints such as time and budget
iii. Size of Testing Team
iv. Size of the Development Team
A. i,ii,iii are true and iv is false
B. i,,iv are true and ii is false
C. i,ii are true and iii,iv are false
D. ii,iii,iv are true and i is false
Answer:C

26.Which of the following will be the best definition for Testing:
A. The goal / purpose of testing is to demonstrate that the program works.
B. The purpose of testing is to demonstrate that the program is defect free.
C. The purpose of testing is to demonstrate that the program does what it is supposed to do.
D. Testing is executing Software for the purpose of finding defects.
Answer:D

27. Minimum Tests Required for Statement Coverage and Branch Coverage:
Read P
Read Q
If p+q > 100 then
Print "Large"
End if
If p > 50 then
Print "pLarge"
End if
A. Statement coverage is 2, Branch Coverage is 2
B. Statement coverage is 3 and branch coverage is 2
C. Statement coverage is 1 and branch coverage is 2
D. Statement Coverage is 4 and Branch coverage is 2
Answer:C

28. Match every stage of the software Development Life cycle with the Testing Life cycle:
i. Hi-level design a Unit tests
ii. Code b Acceptance tests
iii. Low-level design c System tests
iv. Business requirements d Integration tests
A. i-d , ii-a , iii-c , iv-b
B. i-c , ii-d , iii-a , iv-b
C. i-b , ii-a , iii-d , iv-c
D. i-c , ii-a , iii-d , iv-b
Answer:D

29. Which of the following is a part of Test Closure Activities?
i. Checking which planned deliverables have been delivered
ii. Defect report analysis.
iii. Finalizing and archiving testware.
iv. Analyzing lessons.
A. i , ii , iv are true and iii is false
B. i , ii , iii are true and iv is false
C. i , iii , iv are true and ii is false
D. All of above are true
Answer:C

30. Which of the following is NOT part of a high level test plan?
A. Functions not to be tested.
B. Environmental requirements.
C. Analysis of Specifications.
D. Entry and Exit criteria.
Answer:C

31. If a candidate is given an exam of 40 questions, should get 25 marks to pass 61%) and should get 80% for distinction, what is equivalence class.
A. 23, 24, 25
B. 0, 12, 25
C. 30, 36, 39
D. 32,37,40
Answer:D

Example how to create arraylist and bind it to datalist

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
namespace examples_Post
{
public partial class exp9 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Creating the arraylist values to bind them to datalist
ArrayList myarraylist = new ArrayList(3);
myarraylist.Add("Damien");
myarraylist.Add("David");
myarraylist.Add("Campbell");
myarraylist.Add("Cairns");
myarraylist.Add("Anthony");
myarraylist.Add("Cieran");
// Setting the datasource property of datalist to the array 'myarraylist'
dlTest.DataSource = myarraylist;


//Binding the myarraylist values to datalsit
dlTest.DataBind();
}
}
}






==


<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="dlTest" runat="server" ForeColor="#000000" BackColor="Beige"
CellPadding="3" GridLines="none" Width="50%">
<ItemStyle Font-Size="Large" BackColor="Beige"/>
<AlternatingItemStyle Font-Size="Medium" BackColor="Orchid" />
<ItemTemplate>
<%# Container.DataItem %>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>

Console Namespace

by Emmaneale Mendu
 Well, we are done with basic part of classes, by now everyone will know how to use classes. And in this post we will work on a new topic namespaces. Like classes we can have any number of namespaces in our program.
A namespace is nothing but a word and with open brace and close brace. The entire class and group of classes are enclosed within the namespace. Example: as shown below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class abc
    {
        static void Main()
        {
          
        }
    }

    namespace ns1
    {
        class ns1_class
        {
          
        }
    }

    namespace ns2
    {
        class ns2_class
        {
          
        }
    }
}

namespace Consol
{
    class Consol_class
    {
      
    }
}
Here you two main namespaces ‘ConsoleApplication2’ and ‘Consol’and inner namespaces with having group of classes.
I will show you the errors and solutions later in this post.
namespace ConsoleApplication2
{
    class abc
    {
        static void Main()
        {
            ccc();
            aaa();
            bbb();
          
            Console.ReadKey();
        }

        public static void ccc()
        {
            Console.WriteLine("I am in CCC");
        }      
    }

    namespace ns1
    {
        class ns1_class
        {
            public static void aaa()
            {
                Console.WriteLine("I am in AAA");
            }
        }
    }

    namespace ns2
    {
        class ns2_class
        {
            public static void bbb()
            {
                Console.WriteLine("I am in BBB");
            }
        }
    }
}
Errors:
The name ‘aaa’ does not exist in the current context.
The name ‘bbb’ does not exist in the current context.

In the above example program we are calling methods aaa() and bbb() which are in other namespaces. We need tell to the machine from which namespace the method is called. Like as shown in the below code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class abc
    {
        static void Main()
        {
            ns1.ns1_class.aaa();
            ns2.ns2_class.bbb();
            ccc();
          
            Console.ReadKey();
        }

        public static void ccc()
        {
            Console.WriteLine("I am in CCC");
        }      
    }

    namespace ns1
    {
        class ns1_class
        {
            public static void aaa()
            {
                Console.WriteLine("I am in AAA");
            }
        }
    }

    namespace ns2
    {
        class ns2_class
        {
            public static void bbb()
            {
                Console.WriteLine("I am in BBB");
            }
        }
    }
}

OutPut
I am in AAA
I am in BBB
I am in CCC

Now we will little different way to call the other namespace methods adding using’s.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ns1;
using ns2;

namespace ConsoleApplication2
{
    class abc
    {
        static void Main()
        {
            ns1_class.aaa();
            ns2_class.bbb();
            ccc();
          
            Console.ReadKey();
        }

        public static void ccc()
        {
            Console.WriteLine("I am in CCC");
        }      
    }  
}

namespace ns1
{
    class ns1_class
    {
        public static void aaa()
        {
            Console.WriteLine("I am in AAA");
        }
    }
}

namespace ns2
{
    class ns2_class
    {
        public static void bbb()
        {
            Console.WriteLine("I am in BBB");
        }
    }
}

OutPut
I am in AAA
I am in BBB
I am in CCC