Category Archives: ASP.Net

Get ConnectionString From Web.Config File ASP.Net

Get ConnectionString From Web.Config File ASP.Net

In this asp.net post i will explain you how to get or read connectionstring from web.config file in asp.net using c# and vb.net.

We can write out connectionstring string in web.config file as following two ways..

1. Write connectionstring inside  <ConnectionString> </ConnectionString>  tag.
2. Write conectionstring inside <appSettings></appSettings> tag

First way to write connectionstrin inside <ConnectionString> tag in we.config:

Write connectionstring inside ConnectionString tag inWeb.Config file.

We can read conectionstring from web.config file using System.Configuration. First imports System.Configuration namespace for read connectionstring from web.config file.

Read ConnectionString using C# from web.config.

 Read ConnectionString using VB.Net from web.config.

Now. let’s understand second way to read connectionstring from web.config file.

Write connectionstring inside appSettings tag inWeb.Config file.

Read ConnectionString using C# from web.config.

 Read ConnectionString using VB.Net from web.config.

Create and Call Web Service in ASP.Net using C#

In this asp.net post we will learn how to create a web service and how to run and call web service to asp.net web application using c#.

Web service use the SOAP protocol for interface and communication. Web service is a simple web based application which is hosted on server, we can call just web references to use business logic of web service to our web application.

First create a new web service.

Create a web service in ASP.Net C#

Create a web service in ASP.Net using C#

 

web service2

Create a web service in ASP.Net using C#

 

Create a web service in ASP.Net using C#

Create a web service in ASP.Net using C#

Write the web service code at Service.cs file for multiplication and summation.

public class Service : System.Web.Services.WebService
{
public Service () {

//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return “Hello World”;
}

[WebMethod]
public int Sum(int x, int y, int z)
{
return x + y + z;
}

[WebMethod]
public int Multiplication(int x, int y, int z)
{
return x * y * z;
}
}

 

web service3

Create a web service in ASP.Net using C#

web service4

Create a web service in ASP.Net using C#

Create a web service in ASP.Net C#

Create a web service in ASP.Net using C#

Create a web service in ASP.Net using C#

Create a web service in ASP.Net using C#

 

Now,  Create a New ASP.net website to call this web service to asp.net website.

Call web service to ASP.Net website using C#

Call web service to ASP.Net website using C#

web2

Call web service to ASP.Net website using C#

web3

Call web service to ASP.Net website using C#

web4

Call web service to ASP.Net website using C#

web5

Call web service to ASP.Net website using C#

web6

Call web service to ASP.Net website using C#

 

Write below code on button click event for summation and multiplication.

protected void btnSum_Click(object sender, EventArgs e)
{
localhost.Service objservice = new localhost.Service();
int ans = objservice.Sum(Convert.ToInt32(txtA.Text), Convert.ToInt32(txtB.Text), Convert.ToInt32(txtC.Text));
lblans.Text = ans.ToString();
}
protected void btnmultiply_Click(object sender, EventArgs e)
{
localhost.Service objservice = new localhost.Service();
int ans = objservice.Multiplication(Convert.ToInt32(txtA.Text), Convert.ToInt32(txtB.Text), Convert.ToInt32(txtC.Text));
lblans.Text = ans.ToString();
}

 

web7

Call web service to ASP.Net website using C#

web8

Call web service to ASP.Net website using C#

How to learn Responsive Web Design with @media query in asp.net?

We can use @media query in  CSS file.

CSS media queries to assign different stylesheets depending on browser window size.

@media query css style sheet applied according to the browser widths.

We also use @media query to design Responsive website.

Responsive  web design approach, a web page can adjust itself on the device it’s being displayed on.

Example of @media query

Create new website in visual studio, and create new stylesheet in asp.net.

Apply the Stylesheet on webform….

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

<meta name=”viewportcontent=”width=device-width, initial-scale=1” />

<link href=”StyleSheet.css” rel=”stylesheet” type=”text/css” />
</head>
<body>
<form id=”form1″ runat=”server”>
<div>

</div>
</form>
</body>
</html>

The StyleSheets file code :

body
{
background:Blue;
}

@media screen and (max-width:800px)
{
body
{
background:Red;
}

}

Here, we create stylesheet with @media query.

The Stylesheet Describe the body background color Blue of webpage, but when we changed width of browser up to maximum 800px body background color will be Red.

The output of @media query is:

What Is Responsive Web Design

Responsive Web Design with @media query in asp.net

I hope this post well help you…..

 

How to chage DefaultViewMode in DetailView Control in ASP.Net

Here, will learn to change DefaultViewMode of DetailViewControl from ReadOnly to Edit and Insert.

Change DetailView DefaultViewMode from Readonly to Edit….

protected void DetailsView1_ModeChanging(object sender, DetailsViewModeEventArgs e)
{
DetailsView1.ChangeMode(DetailsViewMode.Edit);
}

What is diffrent between windows and web based application?

Web based application:

–          Web application can be access from anywhere in the world through the internet.
–          Web application run on web server (usually IIS and Apache)
–          We need to use Browser to run web application.
–          It is a computer software application that is coded in a browser-supported language (such as HTML, ASP, PHP, Perl, Python etc.)
–          Webservices  & Websites (ASP.NET) are typical web applications.
–          Web applications are very much useful when they are hosted.

 

Windows based Application:

–          Windows based application need to be installed on your machine to access.
–          A program that is written to run under Microsoft’s Windows operating system.
–          Windows applications run on personal computers and work stations.
–          Windows applications (desktop) need to be installed on each client’s PC.
–          Windows application runs faster than Web application.

How to create Assembly in .Net C#.

An assembly is the primary building block of a .NET Framework application.
It is an Output Unit. Assemblies contain MSIL code.
– Assembly physically exist as DLLs or EXEs
– One assembly can contain one or more files
–  The constituent files can include any file types like image files, text files etc. along with DLLs or EXEs
– When you compile your source code by default the exe/dll generated is actually an assembly.

Manifest: Assembly manifest is a data structure which stores information about an assembly
Assembly Metadata is stored in the Manifest.

Metadata: is a data about data.

There are 2 types of assemblies.
1. Private Assembly
2.Shared Assembly (Public) – C:\windows\assembly
By default, assemblies are private.

A private assembly is used only by a single application, and is stored in application folder, or in a subfolder.
When the .net code gets compiled it generates an assembly which is stored in bin folder.

Shared assemblies (also called strong named assemblies) are copied to a single location (usually the Global assembly cache)
– Shared assembly can be used by multiple application and has a strong name.
– Strong name indicate the assembly, Version number, culture identity and public key token.

Now, We learn how to create assembly in asp.net c#.

STEP 1 – First Start the Visual Studio and Create New Class Library Project.

create an assembly in asp.net c#

create an assembly in asp.net c#

STEP 2 – Now we have created Class Library, write below code in Class1.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MeeraLibrary
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class ChangeCharacter
{
public string UpperCase(string text)
{
return text.ToUpper();
}
public string LowerCase(string text)
{
return text.ToLower();
}
}
}

create assembly in asp.net C#

create assembly in asp.net C#

After doing this Build an application, for generate the ClassLibrary1.dll
The ClassLibrary1.dll file automatically generated by compiling the application in Your Application/Bin/Debug Folder.

STEP 3 – Now use the assembly, create a new web application. then add ClassLibray1.dll by add reference to Bin Folder.

add assembly to web application in asp.net c#

add assembly to web application in asp.net c#

After creating a New web application  –> Right Click on Project —> Add Reference
Select Browse option to select the ClassLibrary1.dll which you created before.

Create assembly in asp.net

Create assembly in asp.net

– Now you have added ClassLibrary1.dll in Bin Folder.

create assembly in asp.net C#

create assembly in asp.net C#

Write the below code for design web form:

<body>
<form id=”form1″ runat=”server”>
<div>
</div>
<asp:Button ID=”Button1″ runat=”server” onclick=”Button1_Click” Text=”Upper” />
<asp:Button ID=”Button2″ runat=”server” onclick=”Button2_Click” Text=”Lower” />
<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
</form>
</body>

How to use class library in asp.net c#

How to use class library in asp.net c#

write below code on Button Click Event at code behind page:

protected void Button1_Click(object sender, EventArgs e)
{
MeeraLibrary.ChangeCharacter mm = new  MeeraLibrary.ChangeCharacter();
TextBox1.Text=    mm.UpperCase(TextBox1.Text);
}
protected void Button2_Click(object sender, EventArgs e)
{
MeeraLibrary.ChangeCharacter mm = new MeeraLibrary.ChangeCharacter();
TextBox1.Text = mm.LowerCase(TextBox1.Text);
}

 

I hope you will enjoy this asp.net tutorials about creating assembly.

What is Microsoft Intermediate Language (MSIL) or IL in .Net?

MSIL – Microsoft Intermediate Language in ASP.Net

  • MSIL stands for Microsoft Intermediate Language. We can call it as Intermediate Language (IL) or Common Intermediate Language (CIL).
  • During the compile time, the compiler convert the All .NET source code into Microsoft Intermediate Language (MSIL) .Microsoft Intermediate Language (MSIL) is a CPU-independent set of instructions that can be efficiently converted to the native code.
  • During the runtime the Common Language Runtime(CLR) uses Just In Time(JIT) compiler converts the Microsoft Intermediate Language (MSIL) code into native code to the Operating System.

When a compiler produces Microsoft Intermediate Language (MSIL), it also produces Metadata. The Microsoft Intermediate Language (MSIL) and Metadata are contained in a portable executable (PE) file . Microsoft Intermediate Language (MSIL) includes instructions for loading, storing, initializing, and calling methods on objects, as well as instructions for arithmetic and logical operations, control flow, direct memory access, exception handling, and other operations

What is Just In Time Compiler (JIT) in .NET?

JIT – Just In Time Compiler

– During the code execution time, JIT compiler converts Managed Code (MSIL) to native code/ Machine code for  execution.

– Pre-JIT : Pre-JIT compiles complete source code into native code in a single compilation cycle. This is done at the time of deployment of the application.

– Econo-JIT : Econo-JIT compiles only those methods that are called at runtime. However, these compiled methods are removed when they are not required.

– Normal-JIT: Normal-JIT compiles only those methods that are called at runtime. These methods are compiled the first time they are called and they are stored in cache. When the same methods are called again, the compiled code from cache is used for execution.

The Common Language Runtime (CLR) provides various Just In Time compilers (JIT) and each works on a different architecture depending on Operating System. That is why the same Microsoft Intermediate Language (MSIL) can be executed on different Operating Systems without rewrite the source code. Just In Time (JIT) compilation preserves memory and save time during application initialization. Just In Time (JIT) compilation is used to run at high speed, after an initial phase of slow interpretation. Just In Time Compiler (JIT) code generally offers far better performance than interpreters.

What is Assembly in .NET Framework.

What is Assembly in .NET Framework.

  • An Assembly is a  logical unit of code.
  • Assembly physically exist as DLLs or EXEs.
  • One assembly can contain one or more files.
  • The constituent files can include any file types like image files, text files etc. along with DLLs or EXEs.
  • When you compile your source code by default the exe/dll generated is actually an assembly.
  • When you talk about version of a component you are actually talking about version of the assembly to which the component belongs.
  • Every assembly file contains information about itself. This information is called as Assembly Manifest.

 

Manifest : Assembly manifest is a data structure which stores information about an assembly
Assembly Metadata is stored in the Manifest.

Metadata: is a data about data.
Metadata is a code that describes the compiled MSIL. .NET language compiler will generate the metadata and store this in the assembly containing the MSIL.

Every Assembly you create contains one or more program files and a Manifest. There are two types program files : Process Assemblies (EXE) and Library Assemblies (DLL). Each Assembly can have only one entry point (that is, DllMain, WinMain, or Main). We can create two types of Assembly, private Assembly and shared Assembly . A private Assembly is used only by a single application, and usually it is stored in that application’s install directory. A shared Assembly is one that can be referenced by more than one application. If multiple applications need to access an Assembly, we should add the Assembly to the Global Assembly Cache (GAC).

What is ASP.Net?

ASP.NET

– ASP.net is a tool / Technology for developing a powerful web and windows application using different languages.

– ASP.Net is Microsoft server-side Web technology.

– ASP.net is not a coding language.

– In 2002 Microsoft develop .NET Framework by merging ASP and VB 6.0.

ASP + VB 6.0 = .NET Framework (ASP.Net Product)

ASP.Net with C#

ASP.Net with C#

ASP.Net Framework Release:

1.0 Framwork  –  13/02/2002 Visual Studio .Net
1.1 Framwork  –  24/04/2003  Visual Studio 2003
2.0 Framwork  –  07/11/2005 Visual Studio 2005
3.5 Framwork  –  19/11/2007  Visual Studio 2008
4.0 Framwork  –  12/04/2010  Visual Studio 2010
4.5 Framework –  15/08/2012 Visual Studio 2012

 

ASP.Net is Microsoft server-side Web technology. ASP.NET takes an object-oriented programming approach to Web page execution. Every element in an ASP.NET page is treated as an object and run on the server. An ASP.NET page gets compiled into an intermediate language by a .NET Common Language Runtime-compliant compiler. Then a JIT compiler turns the intermediate code to native machine code, and that machine code is eventually run on the processor

What is Client Side Scripting Language and Server Side Scripting Language

Client Side Scripting Language :

– The client-side Scripting language usually run on Client browser.

– Client side script is a special script that is downloaded and executed at the users end.

– It is completely browser dependent.

– we can download the code.

– Client side scripting cannot be used to connect to the databases on the web server.

– Client side scripting is possible to be blocked by the user.

– Example : HTML, JavaScript, VBScript.

 

Server Side Scripting Language:

– The Server Side Scripting Language run on the Server, where the website is hosted.

– The  server side scripting the script is executed at the server end and the result is sent over to the user end.

– We cannot download the Code.

– Server side scripting is used to connect to the databases that reside on the web server.

– Server side scripting can’t be blocked by the user.

– Example : PHP, JSP,  ASP, ASP.Net, Ruby

What is Common Language Runtime(CLR) in ASP.Net

CLR – Common Lnaguage Runtime

–  CLR is the Foundation of the .NET Framwork and Heart of the .NET Framwork.

–  The Common Language Runtime (CLR) is an Execution Environment.

– All .Net Source code is compiled to MSIL or IL with the help of CLR.

– The main function of Common Language Runtime (CLR) is to convert the Managed Code into native code and then execute the Program.

The Common Language Runtime (CLR)  uses Just In Time(JIT) compiler to converts Intermediate Language (MSIL) to Native code/ Machine code on demand at application run time.

The Common Language Runtime (CLR) environment is also called a managed environment, because all Managed code runs inside the environment of CLR.

Functionality of CLR During the execution of the program:

  • Memory management
  • Thread management
  • Security management
  • Garbage Collection (GC)
  • Code safety verifications