Call Jquery Server side asp.net
i want to use this plugin on my asp.net application. I am serializing my title and text serverside with this class. and i have no problem to show it. but my challenge is : i am loading titles and Contents of notifies from database. i have no problem with load and selecting from Database. i want to refresh notifies on every page load for user. for example 4 row added to Notification Table on database. how can i serialize 4 valuable and binding it to Source and title property of JQUERY notification plugin and displaying 4 notifier to user dynamically ? for 1 valuable that i want to bind to a jquery property plugin i am using this code snippet:
JavaScriptSerializer serializer = new JavaScriptSerializer();
string jsArray = serializer.Serialize(my public Variable that is binded to Jquery plugin);
i am binding public c# valuable to jquery plugin in this type :
title : <%=C# Variable%>
how can i use this method to displaying notifiers to user dynamically? is there any better method? i want to show notifies on all pages. have i to put codes on Basepage? English Is not my frist language . Does my question Clear? thanks all
For example i have 4 new notification in database i am loading them in memory how can i disp开发者_运维技巧laying them as notification to user. i said i have no problem to display one my problem to display them dynamically depend on my updates on database on each page load. thanks all
You'll just have to add a new notify script entry for each entry from your database on page load. This is very basic and you should just replace the hardcoded ID / css classses
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
string notifyScript = "$(\"#container\").notify();$(\"#container\").notify(\"create\", \"basic-template\", { title: '{0}', text: '{1}'},{ expires: false, speed: 1000 });"
Dictionary<string,string> notifications = your titles/text from DB;
foreach(KeyValuePair notification in notifications)
{
notificationScript.Text += String.Format(notifyScript, notification.Key, notification.Value);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<link href="test.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js"></script>
<script type="text/javascript" src="jquery.notify.js"></script>
<title>Show a notify box</title>
<script type="text/javascript">
$(function(){
<asp:Literal ID="notificationScript" runat="server" />
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="default"></div>
<div id="container">
<div id="basic-template">
<a class="ui-notify-cross ui-notify-close" href="#">x</a>
<h1>#{title}</h1>
<p>#{text}</p>
</div>
</div>
</form>
</body>
</html>
精彩评论