我一直在使用相同的Page.clientScript从代码隐藏调用javascript来引用其他项目中的这个链接Calling javascript function from Codebehind并且它已经工作了,但它现在在我当前的项目中不起作用。
这是我的c#代码:
protected void Page_Load(object sender, EventArgs e)
{
Page.LoadComplete += new EventHandler(Page_LoadComplete);
}
void Page_LoadComplete(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("Page Loaded");
var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
if (!namespaceManager.SubscriptionExists(CID, "AllMessages"))
{
namespaceManager.CreateSubscription(CID, "AllMessages");
}
System.Diagnostics.Debug.WriteLine("Sub Existed : " + namespaceManager.SubscriptionExists(CID, "AllMessages"));
client = SubscriptionClient.CreateFromConnectionString(connectionString, CID, "AllMessages");
// OnMessageOptions eventDrivenMessagingOptions = new OnMessageOptions();
// eventDrivenMessagingOptions.ExceptionReceived += OnExceptionReceived;
client.OnMessage(OnMessageArrived);
}
void OnMessageArrived(BrokeredMessage message)
{
System.Diagnostics.Debug.WriteLine("++++++++++++++++++++");
System.Diagnostics.Debug.WriteLine(message.GetBody<UpdateData>().data);
Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "MyFunction()", true);
}
static void OnExceptionReceived(object sender, ExceptionReceivedEventArgs e)
{
}
谢谢。