Domanda

i 'm using SqlDependency for a real-time ASP.NET application. And i'm using some javascript methods on my almost whole project that i can register with ScriptManager like:

ScriptManager.RegisterStartupScript(this, typeof(Page), new Random().Next(0, 9999999).ToString(), "alert('Some Text');", true);

this works everywhere expect inside Onchange event of SqlDependency like:

 SqlDependency dep = new SqlDependency(sqlCommand);
 SqlDependency.Start("my_con_str");
 dep.OnChange += new OnChangeEventHandler(dep_OnChange);
 void dep_OnChange(object sender, SqlNotificationEventArgs e)
 {
    ScriptManager.RegisterStartupScript(this, typeof(Page), new Random().Next(0, 9999999).ToString(), "alert('TEST');", true);
 }

above code doesn't work. But anywhere expect inside of dep_OnChange event RegisterStartupScript is working perfectly.. By the way i tried almost whole register methods of ScriptManager and ClientScript nothing worked..

Note: And i'm pretty sure it's not about SqlDependency it's about events like onChange..

Any help would be appreciated. Thanks.

È stato utile?

Soluzione

I don't think that's going to work, because the ScriptManager needs the Http Context to work; internally, it is using that to access the request/response lifecycle. Since the dependency can change OUTSIDE of that lifecycle, the ScriptManager won't be able to be instantiated because it only works while IN the lifecycle. That is the problem with statics and stateless ASP.NET.

The only real option is to consider a polling mechanism on the client side, or check out HTML 5 server side events with ASP.NET, or even HTML 5 web sockets.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top