C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Check Internet Connection through AJAX


Posted Date: 05 Jul 2008    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: SubhiMember Level: Gold    
Rating: Points: 10



The status of this resource is Pending. The webmaster may be reviewing this resource or have put on hold.


.aspx page
============

Connection Check


On Body call javascript function onload="startPolling()"




public partial class ConnectionCheck : System.Web.UI.Page, ICallbackEventHandler
{
#region ICallbackEventHandler Members
public string GetCallbackResult()
{
if (CanDownloadData())
return "Connected";
else return "Not Connected";
}

public void RaiseCallbackEvent(string eventArgument)
{
}

#endregion

protected void Page_Load(object sender, EventArgs e)
{
//Ajax.Utility.RegisterTypeForAjax(typeof(ConnectionCheck));
RegisterCallbacks();
}


private void RegisterCallbacks()
{
string sbReference = ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
string cbScript = String.Empty;
// check if the script is already registered or not
if (!ClientScript.IsClientScriptBlockRegistered("CallServer"))
{
cbScript = @" function CallServer(arg,context) { " + sbReference + "}";
ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", cbScript, true);
}
}





private bool CanDownloadData()
{
WebClient client = new WebClient();
byte[] data = null;
try
{
data = client.DownloadData("http://www.google.com");
}

catch (Exception ex)
{
}

if (data != null && data.Length > 0) return true;
else return false;
}
}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Check InternetConnection  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Bind DropDownList Through AJAX
Previous Resource: Dynamic Table Through AJAX
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use