"Get Updates : Subscribe to our e-mail newsletter to receive updates........" "Good Luck frnds" Admission 2018 Application Form 2018 Colleges Entrance Exam 2018 Results 2018 Notification 2018 University Educational Jobs 2018 Government Jobs 2018

Search This Blog v24s guys

Follow by Email

03 April, 2013

Check Internet Connection in Asp.net using C#, VB.NET


Here I will explain how to check internet connectivity of system in 
asp.net 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 asp.net. Now I will explain how to check internet connectivity of system in asp.net 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="http://www.w3.org/1999/xhtml" >
<title>Check Internet Connection Availability using Asp.net</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("http://www.google.com");
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("http://www.google.com")
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

Post a Comment

Popular Posts

Recent Posts

Google Analytics