Sep 25

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed

I this article I will explain you how to solve a Jscript runtime error

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed

–>To solve this place this script in page_load event

[code language=”csharp”]

ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(this.lstCustomerRemapping);

[/code]

*lstCustomerRemapping is listview ID.

Keep your required Grid/ListView Ids based upon your requirements.

Happy Coding!!!!

Admin.

 

Sep 14

how to create ms charts in asp. net c#

Hi,In this Article i am going  to explain how to use MSCharts control to draw Charts with the help of SqlServer database data.

Step1:Create table in the Database as below:

1

Step2:In VS2010 add new item to solution with name “MSChart.aspx”

Step3:Paste the below code in “MSChart.aspx”.

[code language=”html”]
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Images.aspx.cs" Inherits="Images" %>

<%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<table cellpadding="4">

<tr>
<td valign="top" align="center">

Chart Type:

<asp:DropDownList ID="ChartType" runat="server" Width="120px" AutoPostBack="True">

<asp:ListItem Value="Column">Column</asp:ListItem>

<asp:ListItem Value="Bar">Bar</asp:ListItem>

<asp:ListItem Value="Pyramid">Pyramid</asp:ListItem>

<asp:ListItem Value="Area">Area</asp:ListItem>

<asp:ListItem Value="Pie">Pie</asp:ListItem>

<asp:ListItem Value="Line">Line</asp:ListItem>

<asp:ListItem Value="Funnel">Funnel</asp:ListItem>

</asp:DropDownList>

</td>

</tr>

<tr>

<td colspan="2">

<asp:Chart ID="Chart1" runat="server" ImageLocation="~/TempImages/ChartPic_#SEQ(300,3)"

Palette="BrightPastel" ImageType="Png" BorderDashStyle="Solid" BackSecondaryColor="White"

BackGradientStyle="TopBottom" BorderWidth="2" BackColor="#D3DFF0" BorderColor="26, 59, 105"

Height="321px" Width="501px">

<BorderSkin SkinStyle="Emboss" />

<Legends>

<asp:Legend Name="Legend1" BackColor="Transparent" Font="Trebuchet MS, 8.25pt, style=Bold"

IsTextAutoFit="False">

</asp:Legend>

</Legends>

<Titles>

<asp:Title Alignment="TopCenter" BackColor="180, 165, 191, 228" BackGradientStyle="TopBottom"

BackHatchStyle="None" Font="Microsoft Sans Serif, 12pt, style=Bold" Name="Revenue"

Text="Revenue" ToolTip="Revenue" ForeColor="26, 59, 105">

</asp:Title>

<asp:Title Alignment="TopCenter" BackColor="Transparent" Font="Microsoft Sans Serif, 10pt, style=Bold "

ToolTip="Chart Type">

</asp:Title>

</Titles>

<Series>

<asp:Series Name="Count" ChartArea="ChartArea1" Legend="Legend1" CustomProperties="DrawingStyle=Cylinder"

BorderColor="64, 0, 0, 0" Color="224, 64, 10" MarkerSize="5">

<EmptyPointStyle AxisLabel="0" />

</asp:Series>

</Series>

<ChartAreas>

<asp:ChartArea Name="ChartArea1" BackColor="64, 165, 191, 228" BackSecondaryColor="White"

BorderColor="64, 64, 64, 64" ShadowColor="Transparent" BackGradientStyle="TopBottom">

<AxisY LineColor="64, 64, 64, 64" IsLabelAutoFit="False" Title="Total Amount" ArrowStyle="Triangle">

<LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" />

<MajorGrid LineColor="64, 64, 64, 64" />

</AxisY>

<AxisX IsLabelAutoFit="False" LineColor="64, 64, 64, 64" Title="FinacialYears" ArrowStyle="Triangle"

Interval="1">

<LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" IsEndLabelVisible="False" Angle="0" />

<MajorGrid LineColor="64, 64, 64, 64" />

</AxisX>

</asp:ChartArea>

</ChartAreas>

</asp:Chart>

</td>

</tr>

</table>

</div>
</form>
</body>
</html>
[/code]

Step4:Paste the below code in “MSChart.cs”.

[code language=”csharp”]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing;
using System.Web.UI.DataVisualization.Charting;

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

Chart();

}
protected void Chart()
{

SqlConnection con = new SqlConnection("Server=Naseer-PC;Database=Naseer;Uid=sa;Pwd=123");
con.Open();
DataSet ds = new DataSet();
string query = "select * from tbl_Mscharts";
SqlCommand cmd = new SqlCommand(query, con);

cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(cmd);

da.Fill(ds, "PremiumData");

if (ds.Tables["PremiumData"].Rows.Count > 0)
{

Chart1.DataSource = ds.Tables["PremiumData"];
// Set series members names for the X and Y values

Chart1.Series["Count"].XValueMember = "Year";

Chart1.Series["Count"].YValueMembers = "Amount";

Chart1.Series["Count"].IsValueShownAsLabel = true;

if (ChartType.SelectedItem.ToString() == "Bar")
{

Chart1.Series["Count"].ChartType = SeriesChartType.Bar;

Chart1.Titles[1].Text = "Bar Chart";

}

else if (ChartType.SelectedItem.ToString() == "Pie")
{

Chart1.Series["Count"]["3DLabelLineSize"] = "100";

Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false;

Chart1.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 15;

Chart1.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 10;

Chart1.ChartAreas["ChartArea1"].Area3DStyle.Perspective = 10;

Chart1.ChartAreas["ChartArea1"].Area3DStyle.IsRightAngleAxes = false;

Chart1.ChartAreas["ChartArea1"].Area3DStyle.WallWidth = 0;

Chart1.ChartAreas["ChartArea1"].Area3DStyle.IsClustered = false;

Chart1.Series[0]["PieDrawingStyle"] = "SoftEdge";

Chart1.Series["Count"].ChartType = SeriesChartType.Pie;

Chart1.Series["Count"]["PieLabelStyle"] = "OutsideInColumn";

Chart1.Series["Count"]["PieOutsideLabelPlacement"] = "Right";

Chart1.Titles[1].Text = "Pie Chart";

}

else if (ChartType.SelectedItem.ToString() == "Line")
{

Chart1.Series["Count"].ChartType = SeriesChartType.Line;

Chart1.Titles[1].Text = "Line Chart";

}

else if (ChartType.SelectedItem.ToString() == "Funnel")
{

Chart1.Series["Count"]["FunnelStyle"] = "YIsHeight";

Chart1.Series["Count"]["FunnelLabelStyle"] = "OutsideInColumn";

Chart1.Series["Count"]["FunnelOutsideLabelPlacement"] = "Right";

Chart1.Series["Count"]["FunnelPointGap"] = "1";

Chart1.Series["Count"]["Funnel3DDrawingStyle"] = "SoftEdge";

Chart1.Series["Count"].ChartType = SeriesChartType.Funnel;

Chart1.Series["Count"]["Funnel3DRotationAngle"] = "5";

Chart1.Series["Count"]["Funnel3DDrawingStyle"] = "CircularBase";

Chart1.Series["Count"]["FunnelMinPointHeight"] = "0";

Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;

Chart1.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 15;

Chart1.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 10;

Chart1.ChartAreas["ChartArea1"].Area3DStyle.Perspective = 10;

Chart1.ChartAreas["ChartArea1"].Area3DStyle.IsRightAngleAxes = false;

Chart1.ChartAreas["ChartArea1"].Area3DStyle.WallWidth = 0;

Chart1.ChartAreas["ChartArea1"].Area3DStyle.IsClustered = false;

Chart1.Titles[1].Text = "Funnel Chart";

}

else if (ChartType.SelectedItem.ToString() == "Area")
{

Chart1.Series["Count"].ChartType = SeriesChartType.Area;

Chart1.Titles[1].Text = "Area Chart";

}

else if (ChartType.SelectedItem.ToString() == "Pyramid")
{

Chart1.Series["Count"]["PyramidLabelStyle"] = "OutsideInColumn";

Chart1.Series["Count"]["PyramidPointGap"] = "1";

Chart1.Series["Count"]["PyramidMinPointHeight"] = "0";

Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;

Chart1.Series["Count"]["Pyramid3DRotationAngle"] = "5";

Chart1.Series["Count"]["Pyramid3DDrawingStyle"] = "SquareBase";

Chart1.Series["Count"]["PyramidValueType"] = "Linear";

Chart1.Series["Count"].ChartType = SeriesChartType.Pyramid;

Chart1.Titles[1].Text = "Pyramid Chart";

}

else
{

Chart1.Series["Count"].ChartType = SeriesChartType.Column;

Chart1.Titles[1].Text = "Column Chart";

}

// Data bind to the selected data source

Chart1.DataBind();

}
}
}
[/code]

Step5:Paste this below code in web.config.

5.1:Place this in Below </roleManager> and in above </system.web> in web.config file  

[code language=”html”]
<httpHandlers>
<add path="ChartImg.axd" verb="GET,HEAD" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
[/code]

5.2:Place this in <system.webServer> in web.config  

[code language=”html”]
<handlers>
<remove name="ChartImageHandler" />
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST"
path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization,   Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
[/code]

Download the Source code From here:MSChats

DataVisualization DLL:DataVisualization

o/p screens:

2

3

4

5

6

7

8

Happy Coding!!!!!!

Admin.

Aug 21

how to disable right click in asp.net web page

In this artical i am going to explain about how to disable right click using Javascript on asp.net page

<%@PageLanguage=”C#”AutoEventWireup=”true”CodeFile=”DisableRightClick.aspx.cs”

   Inherits=”DisableRightClick” %>

<!DOCTYPEhtmlPUBLIC“-//W3C//DTD XHTML 1.0 Transitional//EN”“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<htmlxmlns=”http://www.w3.org/1999/xhtml”>

<headrunat=”server”>

<title></title>

<scriptlanguage=”javascript”type=”text/javascript”>

function disableselect(e)

{

returnfalse

 }

 function reEnable()

{

 returntrue

 }

 //if IE4+        

document.oncontextmenu = new Function(” alert (‘For security reasons, right click was disabled!’ ); return false”)

//if NS6

if (window.sidebar)

{

document.onmousedown = disableselect

document.onclick = reEnable

}    

</script>

</head>

<body>

<formid=”form1″runat=”server”>

<div>

</div>

 </form>

</body>

</html>

–>Simply add the Javascript in the head as above then run your page.

Happy Coding!!!

Admin.

Aug 21

how to copy data from one table to another table in sql server

Hi,In this artical i am going to explain about how to copy data from one table to another table in sqlserver

–>In some cases its necessary to take the backup of your table data while Performing operations like Update,Delete,Insert . Especially,  when we are working with Live data

–>To do that we can also create a table Dynamically and also we can Copy Data from one table to another table by using below syntax.

[code language=”sql”]

Syntax:Select * into NewTable from TableName

[/code]

–>In above the syntax “NewTable” is a table name which will created dynamically when we execute the above syntax,were TableName is existing table.

[code language=”sql”]

Ex:Select * into dbo.Employee_20_8_2013 from  dbo.Employee

[/code]

–>Even we can copy Specified Column by using below syntax

[code language=”sql”]

Syntax:Select column_name into dbo.Employee_20_8_2013 from dbo.Employee

[/code]

Happy Coding!!!

Admin.

Jul 28

How to use Ajax TextBoxWatermarkExtender in asp.net

In this article I am going to explain how to use water mark tool of Ajax toolkit,

–>See in some of the sites we can observe that username and password are shows a tooltip like

Ex: “Enter username” in the textbox this water mark text doesn’t go until we enter data in that particular textbox control

–>See this below figure:

1

–>Here In the above you have to enter username and password in the textboxes; until you enter data in textboxes it will show you the messages

–>Observe the below figures:
2

3

1.To do this open vs

2.Copy and paste below code in the default.aspx

3.Add Ajax toolkit to solution:

[code language=”html”]
<head runat="server">

<title></title>

<script language="javascript" type="text/javascript">

function WaterMark(objtxt, event) {

var defaultText = "Enter UserName";

var defaultpwdText = "Enter Password";

// Condition to check textbox length and event type

if (objtxt.id == "txtId" || objtxt.id == "txtPassword") {

&nbsp;

if (objtxt.value.length == 0 & event.type == "blur") {

&nbsp;

//if condition true then setting text color and default text in textbox

if (objtxt.id == "txtId") {

&nbsp;

objtxt.style.color = "Black";

}

if (objtxt.id == "txtPassword") {

&nbsp;

document.getElementById("txtTempPwd").style.display = "block";

objtxt.style.display = "none";

}

}

}

// Condition to check textbox value and event type

if ((objtxt.value == defaultText || objtxt.value == defaultpwdText) & event.type == "focus") {

if (objtxt.id == "txtId") {

&nbsp;

objtxt.style.color = "Black";

objtxt.value = "";

}

if (objtxt.id == "txtTempPwd") {

&nbsp;

objtxt.style.display = "none";

document.getElementById("txtPassword").style.display = "";

document.getElementById("txtPassword").focus();

}

}

}
</script>

</head>

<body>

&nbsp;

<form id="form1" runat="server">

<div>

<asp:ScriptManager ID="ScriptManager1" runat="server">

</asp:ScriptManager>

<script type="text/javascript" language="JavaScript1.2">

mmLoadMenus();

</script>

<fieldset>

<legend>Ajax WaterMark Example</legend>

<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="left">
&nbsp;
</td>
</tr>
<tr>
<td align="center">
<table width="60%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" style="width: 30%; text-align: left;">
<strong>User Name: </strong>
</td>
<td>
&nbsp;
</td>
<td align="left" style="width: 70%; text-align: left;">
<label>
<asp:TextBox ID="txtUserName" runat="server" BorderWidth="1px" ForeColor="Black"
BorderColor="#FFAB17" ClientIDMode="Static" Height="25px" Width="125px" onblur="WaterMark(this, event);"
BorderStyle="Solid" onfocus="WaterMark(this, event);"></asp:TextBox>
<cc1:TextBoxWatermarkExtender ID="TBWE2" runat="server" TargetControlID="txtUserName"
WatermarkText="Enter UserName" WatermarkCssClass="watermarked" />
</label>
</td>
</tr>
<tr>
<td align="left" style="width: 30%; text-align: left;">
<strong>Password : </strong>
</td>
<td>
&nbsp;
</td>
<td align="left" style="width: 70%; text-align: left;">
<label>
<asp:TextBox ID="txtTempPwd" Text="Enter Password" runat="server" CssClass="text"
BorderWidth="1px" BorderColor="#FFAB17" BorderStyle="Solid" onfocus="WaterMark(this, event);"
Width="125px" Height="25px" ForeColor="Black" ClientIDMode="Static" />
<asp:TextBox ID="txtPassword" BorderWidth="1px" BorderStyle="Solid" TextMode="Password"
Text="Enter Password" runat="server" Width="125px" Height="25px" ForeColor="Black"
CssClass="text" BorderColor="#FFAB17" Style="display: none" onblur="WaterMark(this, event);"
ClientIDMode="Static" />
<cc1:TextBoxWatermarkExtender ID="TBWE3" Enabled="True" runat="server" TargetControlID="txtPassword"
WatermarkText="Enter Password" WatermarkCssClass="watermarked" />
</label>
</td>
</tr>
<tr>
<td height="10" colspan="3">
&nbsp;
</td>
</tr>
</table>
</td>
</tr>
</table>

</fieldset>

&nbsp;

</div>

</form>

</body>
[/code]

Happy coding!!!!!

Admin.

Jul 19

how to export gridview data to excel in asp.net using c#

In this article. I am going to explain about how to Export Data from grid view to Excel sheet:

1.In many cases its very difficult to check the entire data in grid view,so that we can export data into

excel and then we can check  easily.

2.To do that you have to save dataset data in view state and then bind to excel as below:

3.Open sql server create new table “testexport” as below figure.

 

1

4.Insert data into table through your easiest way and bin data to grid view as below figure

 

 

 

2

 

 

5.Click on export button you will get a popup as below

 

 

3

6.Output:-

4

 

5.Click on export button you will get a popup as below

6.Output

Code for this:

In Default.aspx place this Body:

[code language=”html”]

<body>

<form id="form1" runat="server">

<div>

<fieldset id="GdvData" style="width: 25%; text-align: center">

<legend>Grid Data:</legend>

<table>

<tr>

<asp:GridView ID="GDVData" runat="server" AutoGenerateColumns="False">

<Columns>

<asp:BoundField DataField="FirstName" HeaderText="First Name" />

<asp:BoundField DataField="Lastname" HeaderText="Last Name" />

<asp:BoundField DataField="Address" HeaderText="Address" />

</Columns>

</asp:GridView>

</tr>

</table>

</fieldset>

</div>

<div>

<table>

<tr>

<td align="center">

<asp:Button ID="btnExcell" runat="server" Text="Export to Excell" OnClick="btnExcell_OnClick" />

</td>

</tr>

</table>

</div>

</form>

</body>

[/code]

On Default.cs Place this code:

[code language=”csharp”]

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.SqlClient;

using System.Data;

using System.IO;

using System.Text;

public partial class Export : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

BindData();

}

}

protected void BindData()

{

SqlConnection con = new SqlConnection("server=Naseer-PC;uid=sa;password=123;database=Naseer");

string Query = "select * from TestExport";

SqlDataAdapter da = new SqlDataAdapter(Query, con);

DataSet ds = new DataSet();

da.Fill(ds);

if (ds.Tables[0].Rows.Count > 0)

{

GDVData.DataSource = ds;

GDVData.DataBind();

ViewState["ds"] = ds;

}

else

{

ViewState["ds"] = null;

}

}

protected void btnExcell_OnClick(object sender, EventArgs e)

{

try

{

System.IO.StringWriter objStringWriter = new System.IO.StringWriter();

System.Web.UI.WebControls.DataGrid tempDataGrid = new System.Web.UI.WebControls.DataGrid();

System.Web.UI.HtmlTextWriter objHtmlTextWriter = new System.Web.UI.HtmlTextWriter(objStringWriter);

HttpContext.Current.Response.ClearContent();

HttpContext.Current.Response.ClearHeaders();

HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";

HttpContext.Current.Response.Charset = "";

HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=Export.xls");

DataSet ds = (DataSet)ViewState["ds"];

if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)

{

if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)

{

tempDataGrid.DataSource = ds;

}

}

else

{

tempDataGrid.DataSource = null;

}

tempDataGrid.DataBind();

tempDataGrid.HeaderStyle.Font.Bold = true;

tempDataGrid.RenderControl(objHtmlTextWriter);

HttpContext.Current.Response.Write(objStringWriter.ToString());

HttpContext.Current.Response.End();

}

catch (Exception ex)

{

throw ex;

}

}

}

[/code]

Happy Coding!!!

Admin.

Jul 15

How to change Edit/Select top 200/1000 rows to Edit/select all rows in sqlserver2008

In SQL Server 2008, selecting and editing records are 1000 and 200 respectively. Its very Difficult to edit the rows which are above 200 and also time consuming process. To get all the records for selecting and editing we can change as sqlserver2005 menu as below :

1- Open SQL Server 2008 Management Studio

2- Go to Tools

3- Click “Options”

4- Expand the tree of “SQL Server Object Explorer”

5- Click “Commands”

6-Default: “Value for Select Top < n > Audio Records command” as 1000”

6.1-Change: “Value for Select Top < n > Audio Records command” as 0”

7-Default: “Value for edit top < n > rows command” to 200

7.1- Change: “Value for edit top < n > rows command” to 0

8- Default: “Value for select top < n > rows command” to 1000

8.1- Change “Value for select top < n > rows command” to 0

9- Click “OK”

Sqlserver2008

Sqlserver2008-2

Sqlserver2008-3

Sqlserver2008-4

 

In the Last screen we can observe that change is happened it seems to as sqlserver2005.

Happy Coding!!!

Admin.

 

Jul 15

How to get entire information about sqlserver database

In this artical i am going to explain about,how to get entire information about Tables,StoredProcedure and views.

 

–>To get entire information about database

select * from sys.objects

–>To get Total count of StoredProcedures

select Count(*) from sys.procedures

–>To get Total count of Tables

select Count(*) from sys.tables

–>To get Total count of views

select Count(*) from sys.views

–>To get All the Tables from the Database

select * from sys.objects where type=’U’

–>To get All the StoredProcedures from the Database

select * from sys.objects where type=’P’

–>To get All the Views from the Database

select * from sys.objects where type=’V’

 

 

How to search Particular Storedprocedure (or) Table (or) View

1.Ex:Searching for table which is starting with “Tbl”

–>select * from sys.objects where name like  ‘Tbl%’ and type=’U’

2.Ex:Searching for StoredProcedure which is starting with “SP_Val”

–>select * from sys.objects where name like  ‘SP_Val%’ and type=’P’

3.Ex:Searching for View which is starting with “VW_Val”

–>select * from sys.objects where name like  ‘VW_Val%’ and type=’V’

 

 

If you now the Sp name or table name or view name you can search directly as below:

select * from sysobjects where name like ‘%XXXXXXXXXXXXXXXXXX%’

 

Happy Coding!!!!

Admin

 

Jul 06

how to update delete and edit using gridview in asp.net c#

Hi, there this is a common question for all the candidate of .NET in System test

àQuestion is “Bind data to grid view and perform edit and delete operations in grid view

In this article I am going to do the same thing

1.Create a table in database as below

 

Set UserId ad primary key and identity specification àidentity as
“yes”
below

 

Below are the working screens how to Add, Update and Delete

1.Open VS2008/2010

2.File->new WebsiteàAdd ASP.NET website àselect C# language in Installed templates Tab

3.In Default.aspx page paste  this body

[code language=”html”]

<body style="text-align: center">

<form id="form1" runat="server" style="text-align: center">

<fieldset id="grid" style="width: 25%; text-align: center">

<legend>Grid:</legend>

<div id="divreg" runat="server">

<table align="center">

<tr>

<td>

<asp:Label ID="lblid" runat="server" Text="ID"></asp:Label>

</td>

<td>

<asp:TextBox ID="txtID" runat="server" Enabled="false"></asp:TextBox>

</td>

</tr>

<tr>

<td>

User Name:

</td>

<td>

<asp:TextBox ID="txtname" runat="server"></asp:TextBox>

</td>

</tr>

<tr>

<td>

Salary:

</td>

<td>

<asp:TextBox ID="txtsalary" runat="server"></asp:TextBox>

</td>

</tr>

<tr>

<td>

&nbsp;

</td>

<td>

<asp:Button ID="btninsert" runat="server" Text="submit" OnClick="btninsert_Click" />

<asp:Button ID="btnupdate" runat="server" OnClick="btnupdate_Click" Text="Update" />

</td>

</tr>

</table>

</div>

<div id="divgrid" runat="server">

<asp:GridView ID="gdvedit" runat="server" AutoGenerateColumns="false" OnRowCommand="gdvedit_RowCommand"

OnRowEditing="gdvedit_RowEditing" OnSelectedIndexChanged="gdvedit_SelectedIndexChanged"

OnRowDeleting="gdvedit_RowDeleting">

<Columns>

<asp:TemplateField HeaderText="UserID">

<ItemTemplate>

<asp:Label ID="lbluserid" runat="server" Text='<%#Eval("UserID") %>’></asp:Label>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="UserName">

<ItemTemplate>

<asp:Label ID="lblusername" runat="server" Text='<%#Eval("UserName") %>’></asp:Label>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="Salary">

<ItemTemplate>

<asp:Label ID="lblsalary" runat="server" Text='<%#Eval("Salary") %>’></asp:Label>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="Edit">

<ItemTemplate>

<asp:LinkButton ID="lnkbtn" runat="server" Text="Edit" CommandName="Edit" CommandArgument='<%#Eval("UserID") %>’></asp:LinkButton>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="Delete">

<ItemTemplate>

<asp:LinkButton ID="lnkbtn1" runat="server" Text="Delete" CommandArgument='<%#Eval("UserID") %>’

CommandName="Delete"></asp:LinkButton>

</ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

<asp:LinkButton ID="lkbAddnew" runat="server" OnClick="lkbAddnew_Click">Add New Record</asp:LinkButton>

</div>

</fieldset>

</form>

</body>

[/code]

4.Open Default.cs paste this code

[code language=”csharp”]

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient;

public partial class grid : System.Web.UI.Page

{

SqlConnection con = new SqlConnection("server=Naseer-PC;database=Naseer;uid=sa;password=123");

protected void Page_Load(object sender, EventArgs e)

{

btnupdate.Visible = false;

btninsert.Visible = true;

divreg.Visible = false;

divgrid.Visible = true;

if (!IsPostBack)

{

gridbind();

}

}

protected void gdvedit_RowCommand(object sender, GridViewCommandEventArgs e)

{

if (e.CommandName == "Edit")

{

btnupdate.Visible = true;

btninsert.Visible = false;

divreg.Visible = true;

divgrid.Visible = false;

string id =Convert.ToInt32(e.CommandArgument).ToString();

SqlDataAdapter da = new SqlDataAdapter("select * from Logindata where userid=’"+id+"’",con);

DataSet ds = new DataSet();

da.Fill(ds);

DataTable dt = new DataTable();

dt=ds.Tables[0];

if (dt.Rows.Count > 0)

{

txtID.Text = dt.Rows[0]["Userid"].ToString();

txtname.Text = dt.Rows[0]["UserName"].ToString();

txtsalary.Text = dt.Rows[0]["Salary"].ToString();

}

}

if (e.CommandName == "Delete")

{

divreg.Visible = false;

divgrid.Visible = true;

string id = Convert.ToInt32(e.CommandArgument).ToString();

string s = "delete from Logindata where userid=’"+id+"’";

SqlCommand cmd = new SqlCommand(s, con);

con.Open();

cmd.ExecuteNonQuery();

con.Close();

gridbind();

}

}

protected void btninsert_Click(object sender, EventArgs e)

{

string s = "insert into Logindata(UserName,Salary) values(‘" + txtname.Text + "’,’" + txtsalary.Text + "’)";

SqlCommand cmd = new SqlCommand(s, con);

con.Open();

cmd.ExecuteNonQuery();

con.Close();

gridbind();

}

public void gridbind()

{

SqlDataAdapter da = new SqlDataAdapter("select * from Logindata",con);

DataSet ds = new DataSet();

da.Fill(ds);

gdvedit.DataSource = ds.Tables[0];

gdvedit.DataBind();

}

protected void gdvedit_SelectedIndexChanged(object sender, EventArgs e)

{

}

protected void gdvedit_RowEditing(object sender, GridViewEditEventArgs e)

{

}

protected void btnupdate_Click(object sender, EventArgs e)

{

string s = "update Logindata set UserName=’" + txtname.Text + "’,Salary=’" + txtsalary.Text + "’ where Userid=’" + txtID.Text + "’";

SqlCommand cmd = new SqlCommand(s, con);

con.Open();

cmd.ExecuteNonQuery();

con.Close();

gridbind();

divgrid.Visible = true;

divreg.Visible = false;

}

protected void lkbAddnew_Click(object sender, EventArgs e)

{

Clear();

divgrid.Visible = false;

divreg.Visible = true;

btnupdate.Visible = false;

btninsert.Visible = true;

lblid.Visible = false;

txtID.Visible = false;

}

protected void gdvedit_RowDeleting(object sender, GridViewDeleteEventArgs e)

{

}

protected void Clear()

{

txtname.Text = "";

txtsalary.Text = "";

}

}

[/code]

Happy Coding!!!!

Admin.

Apr 20

.net framework and architecture

The .NET Framework is a new and revolutionary platform created by Microsoft for developingapplications.

  • It is a platform for application developers.
  • It is a Framework that supports Multiple Language and Cross language integration.
  • IT has IDE (Integrated Development Environment).
  • Framework is a set of utilities or can say building blocks of your application system.
  • .NET Framework provides GUI in a GUI manner.
  • .NET is a platform independent but with help of Mono Compilation System (MCS). MCS is a middle level interface.
  • .NET Framework provides interoperability between languages i.e. Common Type System (CTS) .
  • .NET Framework also includes the .NET Common Language Runtime (CLR), which is responsible for maintaining the execution of all applications developed using the .NET library.
  • The .NET Framework consists primarily of a gigantic library of code.
Definition: A programming infrastructure created by Microsoft for building, deploying, and running applications and services that use .NET technologies, such as desktop applications and Web services.

Cross Language integration

You can use a utility of a language in another language (It uses Class Language Integration).
.NET Framework includes no restriction on the type of applications that are possible. The .NET Framework allows the creation of Windows applications, Web applications, Web services, and lot more.
The .NET Framework has been designed so that it can be used from any language, including C#, C++, Visual Basic, JScript, and even older languages such as COBOL.

Difference between Visual Studio and Visual Studio .NET

Visual Studio
Visual Studio
It is object based
It is object oriented
Internet based application
– Web Application
– Web services
– Internet enable application
– Third party API
– Peer to peer Application
All developing facilities in internet based application
Poor error handling Exception/Error
Advance error handler and debugger
Memory Management System Level Task
Memory Management Application Domain with help of GC (Garbage Collector)
DLL HELL
VS .NET has solved DLL HELL Problem

Simple explanation of definition used in the above comparision:

Web Application

All websites are example of web application. They use a web server.

Internet Enabled Application

They are desktop application. Yahoo messenger is an example of desktop application.

Peer to Peer

Communication through computers through some system.

Web Services

It doesn’t use web-based server. Internet payment systems are example of web services.

DLL Hell

“DLL Hell” refers to the set of problems caused when multiple applications attempt to share a common component like a dynamic link library (DLL) or a Component Object Model (COM) class.
The reason for this issue was that the version information about the different components of an application was not recorded by the system. (Windows Registry cannot support the multiple versions of same COM component this is called the dll hell problem.)
.Net Framework provides operating systems with a Global Assembly Cache (GAC). This Cache is a repository for all the .Net components that are shared globally on a particular machine. When a .Net component is installed onto the machine, the Global Assembly Cache looks at its version, its public key, and its language information and creates a strong name for the component. The component is then registered in the repository and indexed by its strong name, so there is no confusion between different versions of the same component, or DLL.

Architecture of .NET Framework

Architecture of CLR

 

CLS (Common Language Specification)

It is a subset of CTS. All instruction is in CLS i.e. instruction of CTS is written in CLS.

Code Manager

Code manager invokes class loader for execution.
.NET supports two kind of coding
1) Managed Code
2) Unmanaged Code

Managed Code

The resource, which is with in your application domain is, managed code. The resources that are within domain are faster.
The code, which is developed in .NET framework, is known as managed code. This code is directly executed by CLR with help of managed code execution. Any language that is written in .NET Framework is managed code.
Managed code uses CLR which in turns looks after your applications by managing memory, handling security, allowing cross – language debugging, and so on.
Unmanaged Code
The code, which is developed outside .NET, Framework is known as unmanaged code.
Applications that do not run under the control of the CLR are said to be unmanaged, and certain languages such as C++ can be used to write such applications, which, for example, access low – level functions of the operating system. Background compatibility with code of VB, ASP and COM are examples of unmanaged code.
Unmanaged code can be unmanaged source code and unmanaged compile code.
Unmanaged code is executed with help of wrapper classes.
Wrapper classes are of two types: CCW (COM callable wrapper) and RCW (Runtime Callable Wrapper).
Wrapper is used to cover difference with the help of CCW and RCW.

COM callable wrapper unmanaged code

Runtime Callable Wrapper unmanaged code

Native Code

The code to be executed must be converted into a language that the target operating system understands, known as native code. This conversion is called compiling code, an act that is performed by a compiler.
Under the .NET Framework, however, this is a two – stage process. With help of MSIL and JIT.
MSIL (Microsoft Intermediate Language)
It is language independent code. When you compile code that uses the .NET Framework library, you don’t immediately create operating system – specific native code.
Instead, you compile your code into Microsoft Intermediate Language (MSIL) code. The MSIL code is not specific to any operating system or to any language.
JIT (Just-in-Time)
Just – in – Time (JIT) compiler, which compiles MSIL into native code that is specific to the OS and machine architecture being targeted. Only at this point can the OS execute the application. The just – in – time part of the name reflects the fact that MSIL code is only compiled as, and when, it is needed.
In the past, it was often necessary to compile your code into several applications, each of which targeted a specific operating system and CPU architecture. Often, this was a form of optimization.
This is now unnecessary, because JIT compilers (as their name suggests) use MSIL code, which is independent of the machine, operating system, and CPU. Several JIT compilers exist, each targeting a different architecture, and the appropriate one will be used to create the native code required.
The beauty of all this is that it requires a lot less work on your part – in fact, you can forget about system – dependent details and concentrate on the more interesting functionality of your code.
JIT are of three types:
  1. Pre JIT
  2. Econo JIT
  3. Normal JIT

Pre JIT

It converts all the code in executable code and it is slow

Econo JIT

It will convert the called executable code only. But it will convert code every time when a code is called again.

Normal JIT

It will only convert the called code and will store in cache so that it will not require converting code again. Normal JIT is fast.

Assemblies

When you compile an application, the MSIL code created is stored in an assembly. Assemblies include both executable application files that you can run directly from Windows without the need for any other programs (these have a .exe file extension), and libraries (which have a .dll extension) for use by other applications.
In addition to containing MSIL, assemblies also include meta information (that is, information about the information contained in the assembly, also known as metadata) and optional resources (additional data used by the MSIL, such as sound files and pictures).
The meta information enables assemblies to be fully self – descriptive. You need no other information to use an assembly, meaning you avoid situations such as failing to add required data to the system registry and so on, which was often a problem when developing with other platforms.
This means that deploying applications is often as simple as copying the files into a directory on a remote computer. Because no additional information is required on the target systems, you can just run an executable file from this directory and (assuming the .NET CLR is installed) you’re good to go.
Of course, you won’t necessarily want to include everything required to run an application in one place. You might write some code that performs tasks required by multiple applications. In situations like that, it is often useful to place the reusable code in a place accessible to all applications. In the .NET Framework, this is the Global Assembly Cache (GAC). Placing code in the GAC is simple – you just place the assembly containing the code in the directory containing this cache.

Garbage Collection (GC)

One of the most important features of managed code is the concept of garbage collection. This is the .NET method of making sure that the memory used by an application is freed up completely when the application is no longer in use.
Prior to .NET this was mostly the responsibility of programmers, and a few simple errors in code could result in large blocks of memory mysteriously disappearing as a result of being allocated to the wrong place in memory. That usually meant a progressive slowdown of your computer followed by a system crash.
.NET garbage collection works by inspecting the memory of your computer every so often and removing anything from it that is no longer needed. There is no set time frame for this; it might happen thousands of times a second, once every few seconds, or whenever, but you can rest assured that it will happen.
Will try to explain the processing in terms of C# code which is written using .NET Framework.
Step 1- Application code is written using a .NET – compatible language C#.

 

Step 2 – Code is compiled into MSIL, which is stored in an assembly (see Figure 1 – 2).

 

Step 3 – When this code is executed (either in its own right if it is an executable or when it is used from other code), it must first be compiled into native code using a JIT compiler.

 

Step 4 – The native code is executed in the context of the managed CLR, along with any other running applications or processes.

Note:  One additional point concerning this process. The C# code that compiles into MSIL in step 2 needn’t be contained in a single file. It’s possible to split application code across multiple source code files, which are then compiled together into a single assembly. This extremely useful process is known as linking.
This is because it is far easier to work with several smaller files than one enormous one. You can separate out logically related code into an individual file so that it can be worked on independently and then practically forgotten about when completed.
This also makes it easy to locate specific pieces of code when you need them and enables teams of developers to divide up the programming burden into manageable chunks, whereby individuals can check out pieces of code to work on without risking damage to otherwise satisfactory sections or sections other people are working on.

Conclusion

I hope that this article would have helped you in understanding .NET Framework and have built a simple and clear understanding of .NET.
Happy Coding!!!!!!!!
Admin

Older posts «

» Newer posts