Click here to Skip to main content
15,900,589 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Internet_Connectivity.aspx.cs" Inherits="Internet_Connectivity" %>

<!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>How to check user internet connection</title>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
    <asp:Label runat="server" ID="lblCaption" Font-Bold="true" ForeColor="DarkBlue">To test your connection click below
    

    

    <asp:Button runat="server" ID="cmdCHeck" Text="Check Connectivity" OnClick="cmdCHeck_Click" />
    </div>
    </form>
</body>
</html>


C#
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;

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

    }
    protected void cmdCHeck_Click(object sender, EventArgs e)
    {
        WebClient workstation = new WebClient();
        byte[] data = null;
        try
        {
            data = workstation.DownloadData("http://www.google.com");
        }
        catch (Exception ex)
        {
        }
        if (data != null && data.Length > 0) 
            lblCaption.Text="You are connected.";
        else
            lblCaption.Text="You are not connected.";
    }
}
Posted
Updated 30-Nov-11 20:15pm
v2
Comments
gokulnath1 1-Dec-11 2:12am    
what is ur query????
Sergey Alexandrovich Kryukov 1-Dec-11 2:15am    
Not a question. Format your code and ask one.
--SA

1 solution

How do you expect that to work?
If I need to go to a website to check my internet connection is working, why would I have to press a button to find out?
If I can see the damn button, I have connected to the internet and it is working...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900