jquery通知弹出窗口 - jquery和updatepanels
嗨,我想通知弹出如果需要出现。我正在使用一个asp.net计时器来检查是否有新消息到达。我得到的问题是,jquery通知不显示。我猜这是与更新面板有关的事情。因为当我试图从页面加载调用它时,它工作正常。这是我的代码;jquery通知弹出窗口 - jquery和updatepanels
protected void updateTimer_OnTick(object sender, EventArgs e)
{
Cache Cache = new Cache();
users = Cache.getUserDetailsByUserID(Convert.ToInt32(Page.User.Identity.Name));
if (users._bNewNotification)
{
List<UserNotification> listUserNotification = null;
listUserNotification = Cache.getLatestNotifcationsByUserID(Convert.ToInt32(Page.User.Identity.Name));
foreach (UserNotification userNotification in listUserNotification)
{
StringBuilder jquery2 = new StringBuilder();
jquery2.AppendLine("$.extend($.gritter.options, {");
jquery2.AppendLine("position: 'bottom-left',");
jquery2.AppendLine("fade_in_speed: 100,");
jquery2.AppendLine("fade_out_speed: 100,");
jquery2.AppendLine("time: 3000");
jquery2.AppendLine("});");
Page.ClientScript.RegisterStartupScript(typeof(Page), Guid.NewGuid().ToString(), jquery2.ToString(), true);
StringBuilder jquery1 = new StringBuilder();
jquery1.AppendLine(" var unique_id = $.gritter.add({");
jquery1.AppendLine(" title: 'This is a sticky notice!',");
jquery1.AppendLine(" text: '" + userNotification._NotificationType + "',");
jquery1.AppendLine(" image: 'http://s3.amazonaws.com/twitter_production/profile_images/132499022/myface_bigger.jpg',");
jquery1.AppendLine(" sticky: true,");
jquery1.AppendLine(" time: '',");
jquery1.AppendLine(" class_name: 'my-sticky-class'");
jquery1.AppendLine(" });");
Page.ClientScript.RegisterStartupScript(typeof(Page), Guid.NewGuid().ToString(), jquery1.ToString(), true);
}
users._bNewNotification = false;
users.UpdateNewNotification();
Cache.RemoveUserProfileCacheByUserID(users._USERS_ID);
}
}
有人可以帮助我弄清楚它是什么,我做错了,感谢
你的做法是行不通的。当浏览器得到你的页面时,它会断开连接,所以你的服务器端的C#定时器事件处理程序代码将没有浏览器可以与之通话。
您需要做一些工作,如在客户端 JavaScript中的网页上执行轮询。例如
<script>
$(document).ready(function(){
window.setInterval(function(){
$.get('path/to/GetNotifications.aspx', function(data){
// data contains text from GetNotifications.aspx
// it could be JSON, XML, CSV... it's up to you
// do something with it here...
})
},5000 /*5s*/)
})
</script>
嗨感谢您的回应,我想返回上面我的stringbuilder中的jquery,我该如何去做,如果听起来像一个愚蠢的问题抱歉。 – pmillio 2011-06-16 13:36:58
就像我说的:你的方法不行。您只需将客户端轮询代码嵌入到ASPX页面中,然后编写一个“服务”页面,为您检索通知。 – 2011-06-17 16:07:07
你看过一个Javascript调试器/浏览器控制台来检查运行时错误吗? – foxy 2011-06-16 11:35:44
是的,没有错误被抛出。我需要重新加载我的JavaScript文件,因为我知道该函数依赖于正在加载的文件? – pmillio 2011-06-16 11:49:51