Click here to Skip to main content
15,920,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My Script

JavaScript
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
        var $= jQuery.noConflict();
        function FillNotifications() {
            $.ajax({
                type: "POST",
                url: "home.aspx/GetNotifications",
                data: '{}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,
                failure: function (response) {
                    alert(response.d);
                },
                error: function (response) {
                    alert(response.d);
                }
            });
        }

        function OnSuccess(response) {
            var table = $("#dvNotification table").eq(0).clone(true);
            var Notifications = response.d;
            $("#dvNotification table").eq(0).remove();
            $(Notifications).each(function () {
                $(".shownotificationsid", table).html(this.shownotificationsid);
                $(".notificationid", table).html(this.notificationid);
                $(".subject", table).html(this.subject);
                $(".message", table).html(this.message);
                $("#dvNotification").append(table).append("<br />");
                table = $("#dvNotification table").eq(0).clone(true);
            });
        }

        function ShwoNotification() {
            FillNotifications();
            $("#divnotify").fadeIn("slow");
        }

        $(function () {
            setInterval('ShwoNotification()', 5000);
        });

        $(document).ready(function () {
            $("#closenotify").click(function () {
                $("#divnotify").fadeOut("slow");
            });
        });

        

    </script>


Repeater design Code
ASP.NET
<div id="dvNotification">
                                        <asp:Repeater ID="repnotification" runat="server">
                                            <ItemTemplate>
                                                <tr style="removed: pointer;" >
                                                    <td style="width: 50%;">
                                                        <%# Eval("subject")%>
                                                    </td>
                                                    <td style="width: 30%;"><%#Eval("message")%></td>
                                                </tr>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                        </div>


My Code behind(C#)
C#
public class Notifications
        {
            public string shownotificationsid { get; set; }
            public string notificationid { get; set; }
            public string subject { get; set; }
            public string message { get; set; }
        }

        [WebMethod]
        public static List<Notifications> GetNotifications()
        {
            string constr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
            using (SqlConnection con = new SqlConnection(constr))
            {
                using (SqlCommand cmd = new SqlCommand("SELECT * FROM ShowNotifications where showstatus=1 and toid=" + HttpContext.Current.Session["EmployeeId"] + ""))
                {
                    cmd.Connection = con;
                    List<Notifications> notifications = new List<Notifications>();
                    con.Open();
                    using (SqlDataReader sdr = cmd.ExecuteReader())
                    {
                        while (sdr.Read())
                        {
                            notifications.Add(new Notifications
                            {
                                shownotificationsid = sdr["shownotificationsid"].ToString(),
                                notificationid = sdr["notificationid"].ToString(),
                                subject = sdr["subject"].ToString(),
                                message = sdr["message"].ToString(),
                            });
                        }
                    }
                    con.Close();
                    return notifications;
                }
            }
        }


When I checked console on
JavaScript
$.ajax({

i am getting this error

VM1552:1 Uncaught SyntaxError: Unexpected end of input(…)


FillNotifications @ home.aspx:303
ShwoNotification @ home.aspx:334
(anonymous function) @ VM336:1


So please help me to find out where i did mistake.....

What I have tried:

Above Code Provided for what i tried and where did i got error....
Posted
Updated 14-Jun-16 0:32am
v2
Comments

1 solution

Repeater is a server-side data bound control. It would be a pain to mix your client-side code with server controls as you will not be utilizing some features it may offers.

Instead I would recommend you to consider moving the Repeater's functionality to the client-side like: Use jQuery and ASP.NET AJAX to build a client side Repeater | Encosia[^]

Doing it that way, functionality like paging and sorting is not very difficult to add.Easily build powerful client-side AJAX paging, using jQuery | Encosia[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900