aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Check Internet Connection in using C#, VB.NET

Dec 29, 2012

Here I will explain how to check internet connectivity of system in using C# and VB.NET.

In previous articles I explained
Change the style of tooltip in jQuery, jQuery Countdown timer script example, jQuery Increase or Decrease font size of website, Redirect to another page after some time delay, jQuery slideUp slideDown toggle effects and many articles relating to JQuery and Now I will explain how to check internet connectivity of system in using C# and VB.NET.

We can check internet connectivity of system by downloading data of one website from server for that write code like as shown below

<html xmlns="" >
<title>Check Internet Connection Availability using</title>
<form id="form1" runat="server">
<asp:Button runat="server" ID="btnCheck" Text="Check Internet Connectivity" OnClick="btnCheck_Click" />
<asp:Label runat="server" ID="lbltxt" />
Now in code behind add the following namespaces

C# Code

using System;
using System.Net;
After that write the following code in code behind

protected void btnCheck_Click(object sender, EventArgs e)
WebClient client = new WebClient();
byte[] datasize = null;
datasize = client.DownloadData("");
catch (Exception ex)
if (datasize != null && datasize.Length > 0)
lbltxt.Text = "Internet Connection Available.";
lbltxt.Text = "Internet Connection Not Available.";

Imports System.Net
Partial Class VBCode
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

End Sub
Protected Sub btnCheck_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim client As New WebClient()
Dim datasize As Byte() = Nothing
datasize = client.DownloadData("")
Catch ex As Exception
End Try
If datasize IsNot Nothing AndAlso datasize.Length > 0 Then
lbltxt.Text = "Internet Connection Available."
lbltxt.Text = "Internet Connection Not Available."
End If
End Sub
End Class

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Anonymous said...

nice article

dissertation writing said...

Very clear explanation of issues is given and it is open to everyone.It contains true and fair information. Your website is very useful.

Anonymous said...

what is the use if there is no internet connection to navigate in a website? just curious..please guide me..

Mark Wright said...
This comment has been removed by a blog administrator.
ASd said...
This comment has been removed by a blog administrator.

Give your Valuable Comments

Other Related Posts

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.