Difference Between Compiler and Interpreter

What is the difference between Compiler and Interpreter?

Compiler: -


A compiler is a program that translates program (called source code) written in some high level language into object code.A compiler translates high-level instructions directly into machine language and this process is called compiling.

Interpreter: -


An interpreter translates high-level instructions into an intermediate form, which it then executes. Interpreter analyzes and executes each line of source code in succession, without looking at the entire program; the advantage of interpreters is that they can execute a program immediately.
Read More

Difference Between Managed Code an UnManaged Code in Asp.net

What is the difference between Managed code and unmanaged code?

Managed Code:-


Code that runs under a "contract of cooperation" with the common language runtime. Managed code must supply the metadata necessary for the runtimeto provide services such as memory management, cross-language integration, code access security, and automatic lifetime control of objects. All code based on Microsoft intermediate language (MSIL) executes as managed code.

Un-Managed Code:-


Code that is created without regard for the conventions and requirements of the common language runtime. Unmanaged code executes in the common language runtime environment with minimal services (for example, no garbage collection, limited debugging, and so on).
Read More

Asp.Net Web Forms

Web Forms

It is one of the Three different programming models you can use to create ASP.NET web applications, the others being ASP.NET MVC and ASP.NET Web Pages. ASP.NET Web Forms is a part of the ASP.NET web application framework.
Web Forms are pages that your users request through their browser and that form the user interface (UI) that give your web applications their look and feel. Web form is a combination of HTML, server controls, and server code. When users request a page, it is compiled and executed on the server, and then it generates the HTML markup that the browser can render.

Description 

In previous posts I explained  Value and Reference Types, Asp.net View State, What is the Dataset in ASP.NET,  Difference between .NET Framework 4.5 and .NET Framework 4.0Basics of ASP.NET Now I will explain how to Create Web Form in asp.net using c# .

Step 1 :- 

Open Visual studio

Step 2:-

web-form-in-asp.net

Click on FileàNewàwebsite

Step 3:- 

Browse your Folder where you want to save the Project .

Step 4:-

In  ‘Installed  Templates’ (Left side) select your desired language and finally click on ‘ASP.NET Empty Website’
web-form


Step 5:-

Click on ‘Solution Explorer’ (right side)

Step 6:-

Right click on the   Project path and Click on ‘Add New Item’

Step 7:-

In  ‘Installed  Templates’ (Left side) select your desired language, and click to ‘Add’ button

web-forms

Now a Default.aspx  Web Form has been created in your website.


                                                                                                                                                                                                       







Read More

DataKeyNames Property in asp.net

Here I will explain what is DataKeyNames and uses of DataKeyNames with example in asp.net using c# .

Description:-


In previous posts I explained  Value and Reference Types, Asp.net View State, What is the Dataset in ASP.NET,  Difference between .NET Framework 4.5 and .NET Framework 4.0Basics of ASP.NET Now I will explain what is DataKeyNames and uses of DataKeyNames with example in asp.net using c# .

 DataKeyNames Property in asp.net :-

One of the important properties of all the Data presentation controls in ASP.Net is the "DataKeynames" This is available in all of the data controls like GridView, DetailsView....etc. Most of the time we will assign the primary key of the data to this property. We can assign more than one data column value to this field, separated by a comma. This property need to be important at the time of updating a record from the data control. Now we can look one sample on how this datakeyNames were used in a DataGridView.

DataKeyNames in gridview :-

It generally happens with many developers that they want some value from the datasource to be carried in Asp.net Data controls (ListView, GridView etc) but don't want to show that value in the UI.One traditional way to do this is to bind that value to a column or hidden field and set the control  visibility as false. To get rid of that we can use DataKeys and DataKeyNames property of ListView and GridView. The DataKeyNames property is to specify the field names that we want to carry as hidden, from the data source. For more than one field name we use a comma-separated list of field names.

DataKeyNames = 'Field1, Field2, Field3'

When the DataKeyNames property is set, the ListView control automatically creates a DataKey object for each item (GridViewRow, ListViewDataItem) in the control. The DataKey object contains the values of the field or fields that are specified in the DataKeyNames property. Then it is added to the control's DataKeys collection. This provides a convenient way to access different fields of each item.

Objective


The Objective of this program is to show the data from the rows present in Grid View . From This One can Easily Perform the Event and can Fire any Event and do appropriate Task.
This Program shows a row from Grid View by the click of SHOW button. when a user clicks on the button (Event Fired by an User) and therefore corresponding row data is shown . Through DataKeyNames an userid from Grid View is taken at a time and from that we will have to fetch entire row through command text . And  Meanwhile Entire String is passed as a message and shown to User as Output.

.aspx


<html
xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
  </head>

<body>

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

    <div>

     <table class="style1">

            <tr>

                <td align="center" style="font-family: verdana; font-size: medium; font-weight: bold; font-style: normal; font-variant: normal; text-transform: none; color: #5D7B9D">

                    Displaying Date From Data Key Name</td>
            </tr>
            <tr>
           <td align="left">
         <asp:GridView ID="GridView1" runat="server" Width="60%" DataKeyNames="UserID"
                        AllowPaging="True" PageSize="50" AutoGenerateColumns="False"
                        CellPadding="4" ForeColor="#333333" GridLines="None" >
                        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                      <Columns>
                      <asp:BoundField DataField="UserID" HeaderText="UserId" />
          <asp:BoundField DataField="Sponser_id" HeaderText="Sponser Id" />
        <asp:BoundField DataField="UserName" HeaderText="UserName" />
     <asp:BoundField DataField="Mobile" HeaderText="Mobile" />
      <asp:TemplateField HeaderText="Detail Button">
        <ItemTemplate>
        <asp:Button ID="btn_det" runat="server" Text="Show" OnClick="btn_click" />
        </ItemTemplate>
        </asp:TemplateField>                    
         </Columns>
         <EditRowStyle BackColor="#999999" />
           <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
               <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                        <SortedAscendingCellStyle BackColor="#E9E7E2" />
                        <SortedAscendingHeaderStyle BackColor="#506C8C" />
                        <SortedDescendingCellStyle BackColor="#FFFDF8" />
                        <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                    </asp:GridView>
                </td>
            </tr>
        </table>
   
    </div>
    </form>
</body>
</html>


.CS


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.IO;
using System.Configuration;
public partial class testing:System.Web.UI.Page
{
  SqlConnection cn = new
SqlConnection(ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString);
    SqlCommand cmd = new
SqlCommand();
   protected void Page_Load(object sender, EventArgs e)
    {
       this.fill();
    }
    public void fill()
    {
  cn.Open();
 SqlCommand cmd = new
SqlCommand();
 cmd.Connection = cn;
cmd.CommandText = "select id,UserID,Sponser_id,UserName,Mobile from userDetails";
SqlDataAdapter da = new
SqlDataAdapter();
da.SelectCommand = cmd;
  DataTable dt = new DataTable();
 da.Fill(dt);
 cn.Close();
 GridView1.DataSource = dt;
GridView1.DataBind();
    }
    public void
btn_click(object sender, EventArgs e)
    {
        Button btn = (Button)sender;
        GridViewRow gd = (GridViewRow)btn.Parent.Parent;
        string userid =
GridView1.DataKeys[gd.RowIndex].Value.ToString();
 if (btn.Text == "Show")
 {
 cn.Open();
 SqlCommand cmd = cn.CreateCommand();
cmd.CommandText = "select
UserId,Sponser_id,UserName,LoginType,Mobile from UserDetails where
UserId='"+userid+"'";
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
            string uid = dr["UserId"].ToString();
            string sid = dr["Sponser_id"].ToString();
            string unme = dr["UserName"].ToString();
            string lgnt = dr["LoginType"].ToString();
            string mob = dr["Mobile"].ToString();
           
dr.Close();
cn.Close();
string msg="User Id Is:"+ uid + " Sponser Id Is:"+ sid + " UserName Is :"+ unme + " Login Type Is:" + lgnt+ " Mobile No. is :" + mob;
  string st = "window.alert('"+ msg +"')";
 ScriptManager.RegisterClientScriptBlock(this, this.GetType(),"uniquekey", st,true);    
        }
    }
}
Read More

Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Invalid postback or callback argument.  Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.


For Appropriate Removal Of this Error We Need To Apply [ if (!IsPostBack) ] on the event Where Grid is filled or we can Say that for the Removal of infinite Looping of a method.

or

If You Dont Need to Do All This Lengthy Process you Need to Write  [EnableEventValidation="true"] on .aspx page (ON TOP)


eg-


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridviewbuttoEvent.aspx.cs" Inherits="GridviewbuttoEvent" EnableEventValidation="true" %>
Read More

Asp.net ViewState Example in C-Sharp

Here I will explain what is viewstate and uses of viewstate with example in asp.net using c# .

Description:-


In previous posts I explained What is the Dataset in ASP.NET, Difference between .NET Framework 4.5 and .NET Framework 4.0, What is Cloud Computing, Basics of ASP.NET . Now I will explain what is viewstate and uses of viewstate with example in asp.net using c# .


What is ViewState? 


ViewState is used to maintain the state of controls during page postback and if we save any control values or anything in viewstate we can access those values throughout the page whenever it required for that check below simple example.

.aspx 


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Asp.net ViewState Example in C#, VB.NET</title></head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>ViewState Data:</td><td><b><asp:Label ID="lblViewStateDate" runat="server"/></b></td>
</tr>
<tr><td></td><td> <asp:Button ID="btnClick" runat="server" Text="Get ViewState Data"
onclick="btnClick_Click"/></td></tr>
</table>
</div>
</form>
</body>
</html>

.cs 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
public partial class Test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string str = "Welcome to aspdotnetweb4u";
            if (ViewState["SampleText"] == null)
            {
                ViewState["SampleText"] = str;
            }
        }
    }
    protected void btnClick_Click(object sender, EventArgs e)
    {
        lblViewStateDate.Text = ViewState["SampleText"].ToString();
    }
 }

Read More

What is the Dataset in ASP.NET

Introduction: -

Here I will explain what is Dataset and uses of Dataset with example in asp.net using C# .

Description:-

In previous posts I explained What is Cloud Computing , Difference between .NET Framework 4.5 and .NET Framework 4.0, Basics of ASP.NET. Now I will explain what is Dataset and uses of Dataset with example in asp.net using c# .

What Is Dataset?
A dataset (or data set) is a collection of data.
Most commonly a dataset corresponds to the contents of a single database table, or a single statistical data matrix, where each column of the table represents a particular variable, and each row corresponds to a given member of the dataset in question. The dataset lists values for each of the variables, such as height and weight of an object, for each member of the dataset. Each value is known as a datum. The dataset may comprise data for one or more members, corresponding to the number of rows.

The term dataset may also be used more loosely, to refer to the data in a collection of closely related tables, corresponding to a particular experiment or event.


C# Specifications for code:

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.IO;
using Arahan;

public partial class testing : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString);
    SqlCommand cmd = new SqlCommand();
    DataFill d = new DataFill();

    protected void Page_Load(object sender, EventArgs e)
    {
        this.fillgrd();
    }
    public void fillgrd()
    {
        DataSet dst = new DataSet();
        DataTable dt = new DataTable("People");
        dt.Columns.Add("id");
        dt.Columns.Add("name");
        dt.Columns.Add("Age");
        dt.Rows.Add("1","Amit Singh","21");
        dt.Rows.Add("2","Amitendra","21");
        dst.Tables.Add(dt);
        DataTable ds = new DataTable("new People");
        ds.Columns.Add("id");
        ds.Columns.Add("name");
        ds.Columns.Add("Age");
        ds.Rows.Add("1", "Amitendra", "21");
        ds.Rows.Add("2", "Amit Singh", "21");

        dst.Tables.Add(ds);

        dst.Tables["people"].Rows[0][0].ToString();
        dst.Tables["new People"].Rows[0][0].ToString();
        GridView1.DataSource = dst.Tables["new People"];
        GridView1.DataBind();
       
    }

}

ASPX Code Using Grid View:

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

<!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>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <table class="style1">
            <tr>
                <td align="center"
                    style="font-family: verdana; font-size: medium; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #FFFFFF; background-color: #006699">
                    DataSet Entry</td>
            </tr>
            <tr>
                <td align="left"
                    style="font-family: verdana; font-size: small; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #006699">
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                        BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
                        CellPadding="3">
                        <FooterStyle BackColor="White" ForeColor="#000066" />
                        <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                        <RowStyle ForeColor="#000066" />
                        <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                        <SortedAscendingCellStyle BackColor="#F1F1F1" />
                        <SortedAscendingHeaderStyle BackColor="#007DBB" />
                        <SortedDescendingCellStyle BackColor="#CAC9C9" />
                        <SortedDescendingHeaderStyle BackColor="#00547E" />
                        <Columns>
                        <asp:TemplateField HeaderText="ID">
                        <ItemTemplate><asp:Label ID="lbl_id" runat="server" Text='<%#Eval("id") %>'></asp:Label></ItemTemplate>
                        </asp:TemplateField>    
                        <asp:TemplateField HeaderText="Name">
                        <ItemTemplate>
                        <asp:Label ID="lbl_nme" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
                        </ItemTemplate>
                        </asp:TemplateField>  
                        <asp:TemplateField HeaderText="Age">
                        <ItemTemplate>
                        <asp:Label ID="lbl_age" runat="server" Text='<%#Eval("Age") %>'></asp:Label>
                        </ItemTemplate>
                        </asp:TemplateField>               
                        </Columns>
                    </asp:GridView>
                </td>
            </tr>
        </table>
   
    </div>
    </form>
</body>

</html>


OUTPUT:



Read More

Subscribe via email

Enter your email address:

Delivered by FeedBurner

Blogroll