Wednesday, 31 July 2013

Methods of thread class in .net

The last article has given how the thread being work and what is it.Then we need to know methods which are existing in Thread class.These are used to implement the threads in .net environment.To enable these methods we have to add one name space "System.Threading"to application
1.Start()-->It will start the thread execution["Thread is ready for execution]
2.Current Thread()-->Shared method .It will return thread under execution
3.Sleep(millisecond)-->It will halt thread execution for particular milliseconds
4.suspend()-->It will halt thread execution
5.Resume()-->It will start thread execution which is halted using suspend
6.Method abort();It will stop thread execution(Killing thread execution]
7.Priority:The thread has 3 properties,Which are High,Abnormal,Normal,Below normal,Low
The priority will specify importance /weight-age for thread.The thread with more priority will be given more CPU cycles to finish task quickly

Tuesday, 30 July 2013

multi threading in c# asp.net

1.Thread is a unit of code maintaining its own execution path.
2.The application process with one execution is called single Thread application"
3.The application process with more than one execution path is called "Multi-thread application"
4.CLR will create main thread for .net application process
Example of multi-thread application is ms word

Multithreading is recommended when the application is having a task which can be finished with out user interaction will improve performance of application.The task can be printing job,database connectivity processing client requests to wards server base application

Remoting activation models in .net

Remoting activation model will specify when the object to created where the object to be maintained ,how long the object to be maintained,object to communicate to all the client/unique to client
1.If it is model by value server application will create an object and object will be transmitted to client application.In this case method call's execution will be  in client system.The method execution can not access server side resource like database
2.If it is Marshal by Reference the object will be maintained by server app and reference will be maintained by client system,In this case method call,s the execution will be on server system,This allows accessing Resources
3.Client application making a request to method will create object in server application is called "SAO{server activated Object]"
4.If it is single ton Object,The object will be maintained by server application for serving to other clients,This provides application level state maintaining data common to all the clients.The timeout of single to object is 5 min by default
5.Client application making a call using "New" operator or create instance method of activator class will create an object with in server application is called "Client Activation Object"
6.CAO will maintain data unique to client

Monday, 29 July 2013

Advantages of 3-tier Architecture

1.Less burden on database server[Balancing Load on different system]
2.Less financial investment[Only client side license of data base will be purchase
3.Security resources[Like database] from client
4.Maintenance will be easier[migrating from one database to other database required changes in business layer,it does not require changes in presentation layer,this makes maintenance easier]
5.When business logic maintained on different system it is called "n-Architecture"
Different companies are providing different technologies to implement 3-tier architecture[i:e distributed app development]
i)RPC(Remote Procedure call]this old implements with 'c' language
ii)RMI(Remote method Invocation]this is supported by java
iii)DCOM(Distributed Com)
iv)CORBA{common object request broken Architecture],It is supported by different companies support from Microsoft

Dcom comes with problems
->It supports Microsoft apps communication only under windows network
->It supports only network based implementation ,it doesn,t support internet based implementation
->It implementation supports only client activated implementation,where unique object will be created towards each client,will be burden to server system in certain cases
That solution in .net i 3 things
1.Remoting
2.Web servers
3.Wcf

Thursday, 25 July 2013

populate Asp.net textbox using jquery

As we discuses as the java script is client side programming,But j query is library which is built using java script .Here we need to observe how to get the id of the text box using jquery in asp.net.The one thing we remember when we working with Jquery is"Include the  Library to application".With out add reference we can't perform the  functionality.The below example will show how to populate text box using blur event.When the cursor leaves the first text box the then other one will  be populate.
<html>
<head>
<script type="text/javascript" src="~/jquery-1.4.3.min.js" ></script>
<script type="text/javascript">
$(document).ready(function() {
$("#<%= txtBName.ClientID %>").blur(function(){
var BName = $(this).val();
$("#<%= txtBRname.ClientID %>".val(BName);  

});
});
</script>
</head>
<body>
Enter Book name: <asp:TextBox ID="txtBName" runat="server"></asp:TextBox>
Enter Again:<asp:TextBox ID="txtBRname" runat="server"></asp:TextBox>
</body>
</html>

Wednesday, 24 July 2013

populate textbox with other textbox value in asp.net using javascript

In this articles i will explain about one more standard web control. This control is used to enter the data or can take data from user i:e Text Box.In asp.net Text box has properties to restrict the Lines of data which is Tex Mode property(Single Line and MultiLine).The following example shows how to populate text box with other text box value using Java Script.
                                           Java Script is client side programming which has an event "onblur" to focus functionality.In java script we can't get control value directly.If you want to get the control value,First we need to get the control id using "getElementById" then we can get the value as result.In the above example i have used two text box controls .When the focus has come to second text box ,it will be filled with first Text Box.
<html>
<head>
<script>
function AppendDataToOtherTextBox()
{
var BName=document.getElementById("BooKName");
var BBN=document.getElementById("BooKName1");
BBN.value=BName.value;
}
</script>
</head>
<body>
Enter Book name: <input type="text" id="BooKName" onblur="AppendDataToOtherTextBox()">
Blur Field: <input type="text" id="BooKName1">
</body>
</html>

Tuesday, 23 July 2013

Features of vb.net


1.Vb.net is object oriented programmed language
2.vb.net is not a pure object oriented programming language.because it is not compulsory to create a class in vb.net
3.Vb.net is mot strongly types and type safe language .In vb.net when you assign one type of variable to another type then no need to perform the type casting manual and vb.net will perform type casting
implicitly.Hence it is not strongly types and type safe
4.vb.net is not case sensitive
5.In VisualBasic.net no need to terminate the statements with special character like ";"

Monday, 22 July 2013

Asp.net Get dropdownlist selectedIndex using C#.net

As per previous articles we knew how to get the selected value or text from drop down. Now we will know how to get selected Index of dropdownlist. To do this task i have placed one Drop down and button.In the below code first i make selection on drop down then click on the button .It will print the Index value

<title>Get DropdownList selectedIndex in asp.net</title>
</head>
<body>
<form id="dynamicIndex" runat="server">
<div>
<asp:DropDownList ID="ddlIndex" runat="server">
</asp:DropDownList>
<asp:Button id="btnGetSelectedIndex" runat="server" Text="GetselectedIndex"
onclick="btnGetSelectedIndex_Click" />
</div>
Code behind:
public partial class GetDropdownSelectedIndexDB : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
PopulateddlIndexDB();
}
}
protected void btnGetSelectedIndex_Click(object sender, EventArgs e)
{
int DdlselectedIndex=ddlIndex.SelectedIndex;
Response.Write(DdlselectedIndex.ToString());
}
private void PopulateddlIndexDB()
{
try
{
SqlConnection cni = new SqlConnection(ConfigurationManager.ConnectionStrings["DdlIndexConnectionString"].ToString());
cni.Open();
SqlDataAdapter cai = new SqlDataAdapter("select *from ContentType", cni);
DataSet cdi = new DataSet();
cai.Fill(cdi, "Content");
ddlIndex.DataSource = cdi;
ddlIndex.DataTextField = "Content";
ddlIndex.DataBind();
}
catch (SqlException exi)
{
Response.Write(exi.Message.ToString());
}
finally
{
cni.Close();
}
}
}

Sunday, 21 July 2013

Economical JIT compilation in .net

In economical JIT compilation first the ,net application will be complied by the language compiler into MSIL code and will be permanently saved in a file with extension either exe or dll .While executing the application MSIL code will be loaded as it is into memory by attaching a stab to every method and when you call a method for the first time.
                  Then the stub attached to the method will be redirect the control to JIT compiler that will compile only that particular method to CPU native code and execute it.But when you call the same method again the stub attached to the method will be directly control to memory CPU method native code OS readily available

As MSIL code will not be compiled to CPU native code while loading the app loading application will a fast in the someway during executing also as only one method you call is compiled execution will also be fast

Base class Libraries || Framework class Libraries in .net

Class library logically divided into name space and  will contain types similar to header files in 'c' language..Net provides class libraries but unlike header files a class library in .net will contain types.A type can be a class or structure or enumerator or Interface or a delegate. A class library directly will not contain the types,and it is divided into name space and s will contain that type purpose of the name space is to logically group the related types

When ever you want to use a type available in a class library in your application then you must add the reference of the name space that containing type you want to use to your application and for this purpose vb.net provides "imports" statement and C# provides "using" Statement
And they are similar to # include statement in 'C' language

.Net 4.5 framework provides the assemblies name space and types as follows in different versions please click here

Saturday, 20 July 2013

Asp.net Get dropdownlist selected value using C#.net

Hi all,in previous we have discussed on data bind concepts for dropdownlist.So Then we have to know how get the item data when make a selection on drop down.Here in this example i have used one Asp button and dropdownlist. There are two methods to get the selected value.There is a direct method to get value which is "selected Value"  and the other is Text of selected Index.Please comment if it is helpful
<html>
<head runat="server">
<title>Get DropdownList selectedValue in asp.net</title>
</head>
<body>
<form id="dynamic" runat="server">
<div>
<asp:DropDownList ID="ddlType" runat="server">
</asp:DropDownList>
<asp:Button id="btnGetSelectedvalue" runat="server" Text="Get selected Item value"
onclick="btnGetSelectedvalue_Click" />
</div>
</form>
</body>
</html>

Code behind:
public partial class GetDropdownSelectedvalueDB : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
//PopulateDropdownlist
PopulateddlTypefromDataBase();
}
}
protected void btnGetSelectedvalue_Click(object sender, EventArgs e)
{
//selected value using Text method
string DdlselectedText=ddlType.SelectedIndex.Text;
//Get item using selected value
string Ddlvalue=ddlType.SelectedValue.ToString();
Response.Write(DdlselectedText +"or"+Ddlvalue);
}

private void PopulateddlTypefromDataBase()
{
try
{
SqlConnection cnd = new SqlConnection(ConfigurationManager.ConnectionStrings["DdlConnectionString"].ToString());
cnd.Open();
SqlDataAdapter cad = new SqlDataAdapter("select *from Content", cnd);
DataSet cds = new DataSet();
cad.Fill(cds, "Content");
ddlType.DataSource = cds;
ddlType.DataTextField = "Content_Type";
ddlType.DataBind();
}

catch (SqlException exd)
{
Response.Write(exd.Message.ToString());
}

finally
{
cnd.Close();
}
}
}

Standard JIT Compilation .net

Basically JIT compilation in .net is of 3 types standard JIT compilation,Economical or Ecno JIT compilation and pre-jit compilation.

Standard JIT compilation:-
.Net application-->Language compiler-->MSIL codse-->JIT compiler

In standard JustTimeCompiler first the .net application will be compiled by the language compiler into MSIL(Microsoft Intermediate language) code and will be permanently saved in a file with extension either dll or exe.When you execute the applications,then MSIL code vb compiled by the JIT compiler to CPU ntive code and then application is executed
The CPU native code obtained by compiling MSIL code will not be permanently save and Hence every time you run the application entire MSILbcode of your application must re compiled to CPU native code which will take time.hence the drawback of standard JIT compilation is loading appellation in to memory will be slow

Common Language Runtime in .net

CLR is the run time environment in which .net application are executed CLR forms as a layer on top of as providing it services between .net application of OS.It internally contains other components.


Class Loader:Class loader is responsible for verify the class libraries refered the .net application and load all those class libraries into memory to make them available for .net application.
it is not responsible for loading .net application into memory

Code managers:In .net the code manager is responsible for loading .net application code into memory and managing until the .net application was closed..Net application code is classified into
1.managed code
2.un managed Code

Garbage Collector:
This is responsible for memory management for the .net application.when u create variables and objects in the program then allocates memory for them and de-allocating memory when their lifetime is expired


Security Manager:in .net you can provide the security either by using role based security or code access security.When you provide security by using either of this then verifying the security and executing the security related code is the
responsibility of security manager.Role based security provides the security based on the roles available in OS

Exception Manager:Is response for verifying whether there is any possibility for exception ,raise the exception.If there is possibility,verify whether exception handling code is provided and executing is providing and otherwise terminate the program abnormal

Thread Manager:Executing multiple tasks at a time is called as multitasking.To implement multi tasking u need to create threads with in the application.When you create a thread with in .net application for implementing multitasking executing those threads is the responsibility of thread manager

Just In time compiler:
Every .net language provides its own compiler that compiles the application according to the syntax of that language.But all the compiles of .net language will compile the application to MSIL or CIL code.MSIL is a new low level language created by ms.Advantage of MSIL is it is CPU platform independent.But MSIL code is not understandable by the processor.The JIT compiler in CLR is responsible for compiling  MSIL code to CPU native code understandable by the processor.CLR contains multiple JIT compiles one for each CPU platform

Friday, 19 July 2013

Common Language specification(CLS) and common type system(CTS) in .net

.Net is collection of multiple languages.CLS provides a set of rules and object oriented programming model to be followed by every .net language.when a language follows these set of rules and object oriented programming model then the language said to be CLS compliant i:e the .net language otherwise the language will not be treated as .net language

Common Type System(CTS):In .net every data type is internally represented as a class or structure and they class or structure of the data type provides the methods you can on that type
For example string data type in .net is internally representing with the name "String" and is string class provides the methods like ToLower() using which u ca convert the string to Lowercase and UpperCase

All these classes and structures related to data types are available in CTS even every .net language is providing its own keywords for the data type,internally all .net languages will use the same classes and structures available in CTS

For examples vb.net provides the keyword Integer for storing integer data and C# provides the keyword Int for storing integer data .Buy internally both vb and c# will use the structure in t32 available in CTS. when a variable is declared integer without CTS it is not possible to declare variables in /net application

UnManaged code in .net

.Code for which there is no MSIL executed after the language compile compilation is not executed by the CLR directly rather the CLR will collect all the required resources and redirectly the code to as for execution which is known as unmanaged code And the code execution process is known as unmanaged code execution
For unmanaged code exe CLR does not provide any features of facilities like common
1. data type system
2. Automatic memory management
3. JIT compilation
4. Exception handling mechanism etc

.net source code(Managed code)-->LC-->MSIL-->CLR(unmanagedcode)-->Nativecode-->Code executed

Thursday, 18 July 2013

Bind data to dropdownlist in Asp.net

The rencent posts have given on populate dropdownlist with different source controls.Now i will showing a process which is not used any data source control or generic control.Here we need to create a connection string to data base in configuration file ,then it will be access to code behind file while require to DB connection.After that we can get the data from table using SqlDataAdapter and fill to connection less data set.Finally it has to be used as data source of dropdownlist
<html>
<head runat="server">
<title>Bind Data To DropdownList in asp.net</title>
</head>
<body>
<form id="dynamic" runat="server">
<div>
<asp:DropDownList ID="ddlcollege" runat="server">
</asp:DropDownList>
</div>
</form>
</body>
</html>
Connection String in Web.Config:
<add name="DbJConnectionString" connectionString="Data Source=jyothim\sqlexpress;Initial Catalog=TestDb;Integrated Security=True"
   providerName="System.Data.SqlClient" />
Code behind:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;

public partial class PopulateDropdownListDB : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
PopulateDropdownDynamicallyfromDataBase();
}
}
private void PopulateDropdownDynamicallyfromDataBase()
{
try
{
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["DBjConnectionString"].ToString());
SqlDataAdapter ad = new SqlDataAdapter("select *from CollegeName", con);
DataSet ds = new DataSet();
ad.Fill(ds, "College");
ddlcollege.DataSource = ds;
ddlcollege.DataTextField = "college_name";
ddlcollege.DataBind();
}
catch (SqlException ex)
{
Response.Write(ex.Message.ToString());
}
}
}

Managed Code in .net

1.The code for which MSIL is generated after the language compiler compilation is directly executed by CLR which is known as Managed Code and the code execution process is known as managed code execution
2 .For managed code execution CLR will provide all the facilities or features of .net like
i)Common data type System
ii)Automatic Memory Management
iii)JIT compilation
iv)Code access Security
v)Exception handling Mechanism etc
3.For manage code execution CLR will contain common set of languages rule i;e common language syntax
4.Every programming language syntax will be converted into their common syntax at the time of compilation

Difference between dot net and vs.net

.Net framework is code form .net and it is used to execute .net programs or application.With frame work we can't execute any .net programs.Visual studio .net is just for an editor tool used to build the .net programs or application

.Net Framework
1.Execution environment of .net programs/applications
2.Free software.
3.Occupies a memory of 150mb to 350mb
4.dot net 1.0,2.0,3.0,4.0,4.5 are versions

VisualSTudio.net
1.Desinging/Development environment of .net programs/application
2.It has also free editions
3.Occupies memory of 1.5gb to 3.5GB with out MSDN
4.VS.net2000,2003,2005,2007,2008,2010,2012 are different versions of VS.net

bind data to dropdownlist with arraylist in asp.net

When we working with dropdown list the basic thing we have to know about data binding concepts.As i explained in previous articles we can bind data to controls in several ways .Now i will use Generics which is Array list to bind the data to Dropdownlist.Here the example shows how to add static data to array list then bind to dropdownlist in asp.net.Based on the conditions we have to place the binding function in to page postback event.There is one more thing we need observe i:e "i have used sorting and remove option for names space"
<html>
<head>
<title>Bind Data with ArrayList in Asp.net</title>
</head>
<body>
<form id="Form1" runat="server">
<asp:DropDownList ID="ddlArrayBind" runat="server">
</asp:DropDownList>
<asp:Button id="btnBind" runat="server" Text="Bind Data" 
    onclick="btnBind_Click" />
</form>
</body>
</html>
using System;
using System.Collections;

public partial class BindDatatoDropdownwitharraylist : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
  
}
protected void btnBind_Click(object sender, EventArgs e)
{
    BindatatoDropdownWithArrayList();
}
private void BindatatoDropdownWithArrayList()
{
    ArrayList ArrayItems = new ArrayList();
    ArrayItems.Add("Chip");
    ArrayItems.Add("Mouse");
    ArrayItems.Add("CPU");
    ArrayItems.Add("HardDisk");
    ArrayItems.Add("RAM");
    ddlArrayBind.DataSource = ArrayItems;
    ddlArrayBind.DataBind();
}
}

Wednesday, 17 July 2013

Option statements in vb.net

Vb.net provides three types options statements
Option Explicit On/Off:This option is used to specify weather variable declaration is mandatory in vb.net .By default this option was set  to "ON"that indicates you must declare the variable before using it.When this option was set to "OFF" you can use a variable with out declaring it and in this case the type f variable will be object and it can be store any type of value
Option Explicit off
module module1
sub main()
s1="jyothi"
End sub
End module

Option Strict On/Off
This option is used to specify whether type casting is done implicitly by vb.net or user has to perform manual. By default this option was set to "OFF" indicating vb.net will
implicitly perform typecasting and when this was set to "ON" then user must perform the typecasting manual
Option Strict on
Dim s1 As string="test"
Dim n As Integer=int.Parse(s1)

Option Compare Text/Binary:
This option  is used to specify how the strings will be compared.By default this option is set to "binary" that indicates string will be compared with case sensitivity when this option was set "TEXT" string will be compared with out case sensitivity

Option Compare Text
Dim s1 As string="JYOTHI"
Dim s1 As string="Jyothi"
console.WriteLine(s1=s2)

Difference between Read() and ReadLine() in C#.net

ReadLine():It is used to read the values into variables from the keyboard and it is similar to the library function "scanf" in "C' language
var=Console.ReadLine();
1.ReadLine method will return any value enter to the keyboard as a string
2.vb.net will automatically perform type casting when you read the values for variables other then string
Here i will provide MSDN ReadLine link to get the brief explanation on it.

Read():
1.This method is similar to the library function getch() in "c" language .
2 It is used to read the single character and will not be displayed on the screen
3.MSDN Read() Method

Bind Data to DropdownList using SqlDataSource in Asp.net

Before Going to explain for how get dropdown selected values,we have to know how to bind the data to dropdownlist in asp.net.Here i am using SqlDataSourece control to accomplish the task.By using this we can avoid the code behind (No need to write any code) part.You can see the complete process by going through the below images
<html>
<head>
<title>CheckBoxList Example in Asp.net</title>
</head>
<body>
<form id="Form1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDropdown" 
DataTextField="CityName" DataValueField="City_Id">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDropdown" runat="server" 
ConnectionString="<%$ ConnectionStrings:TestConnectionString %>" 
SelectCommand="SELECT * FROM [City]"></asp:SqlDataSource>
</form>
</body>
</html>
1.Choose data source option from DropdownList Tasks.Then opened a wizard which will be used to select a data source and data filed for dropdowlist

2.Select the data source type and set the name of it.
3.Create a connection string to database.here i have created a test connection string which is used when we want connect to DB
4.Then select the data base table which has to be used for particular application.Then click on next and finish button on next coming wizard
5.Set the data key and data-text field for Dropdownlist using coming up wizard

CheckBoxList Example in Asp.net


CheckBoxList is one of the Asp.net server control.By using this we can make multiple selection while using in application.Here i will explain a simple example to select multiple items for orders.By using button click event i will get the selected item values in the list
<html>
<head>
<title>CheckBoxList Example in Asp.net</title>
</head>
<body>
<form id="Form1" runat="server">
<asp:CheckBoxList ID="ChkList" runat="server">
      <asp:ListItem>Asp.net</asp:ListItem>
      <asp:ListItem>Csharp</asp:ListItem>
      <asp:ListItem>Mvc</asp:ListItem>
      <asp:ListItem>Jquery</asp:ListItem>
      </asp:CheckBoxList>
<asp:button ID="btnSelectedList" text="Get Selected Items" runat="server" onclick="btnSelectedList_Click"/>
<asp:Label id="lblSelectedItems" runat="server" />
</form>
</body>
</html>
CodeBehind:
using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public partial class CheckBoxList : System.Web.UI.Page
{
String selectedItems = "Items";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSelectedList_Click(object sender, EventArgs e)
{
for (int j = 0; j< ChkList.Items.Count; j++)
{
if (ChkList.Items[j].Selected)
{
selectedItems = selectedItems + ChkList.Items[j].Text;
selectedItems = selectedItems + ",";
}
}
lblSelectedItems.Text = selectedItems;
}
}

Tuesday, 16 July 2013

CheckBox example in Asp.net

Aspdotnet provides different kind of standard controls.Here i would like to explain about one of the asp.net server control which is CheckBox. This control can take input as Boolean values.The Boolean value is true when check box checked and its false when it is unchecked.The post-back will also do using the check-box control when this property set to true
In the below example i have changing the color of label ble control when it was checked.For this we have to add system.Drawing namespace to our application
CheckBox.Aspx:
<html>
<head>
<title>CheckBox Example in Asp.net</title>
</head>
<body>
<form id="Form1" runat="server">
<asp:CheckBox id="Chk" Text="Name" runat="server" />
<asp:button ID="btn" text="Check" runat="server" onclick="btn_Click"/>
<asp:Label id="lblName" runat="server" />
</form>
</body>
</html>
CodeBehind:
using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Drawing;

public partial class Checkbox : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_Click(object sender, EventArgs e)
{
if(Chk.Checked==true)
{
    Color Green = Color.FromName("Green");
    lblName.BackColor = Green;
    lblName.Text = "CheckBox checked";

}else
{
    Color Red = Color.FromName("Red");
    lblName.BackColor = Red;
    lblName.Text = "CheckBox Not checked";
}
}
}