| 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; } }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|