0

I have this table on my sql server database:

  1. name
  2. family
  3. address

and i have a 2 user's:

  1. User A
  2. User B

i want to when User B insert new record into the table,show in User A gridView.
i use this solution:
User A web browser has a this code:

<script type="text/javascript">
    $(document).ready(function () {
        setTimeout("RefreshPage()", 5000);

    });
    function RefreshPage() {
       /* var url = "GetOrder.aspx";
        $(location).attr("href", url);
        */
        location.reload();

    };



</script><br/>

that code refresh User A webpage every 5 second and in page load event i write a simple code to run select query and show in gridview.
this method very crazy solution to do this.
can i use other solution and how?

2 Answers2

2

Your code Refresh whole page. Use below code, it will refresh only contain. :)

<asp:ScriptManager ID="scp1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="up1" runat="server">
    <ContentTemplate>
        <asp:GridView ID="yourGrid" runat="server"></asp:GridView>
        <asp:Button id="btnAutoRefresh" runat="server" style="display:none" 
            onclick="btnAutoRefresh_Click" />
    </ContentTemplate>
</asp:UpdatePanel> 

<script type="text/javascript">
    $(document).ready(function () {
        setInterval("RefreshPage()", 5000);

    });
    function RefreshPage() {
        $("#<%=btnAutoRefresh.ClientID %>").trigger("click");

    };    
</script>  

// code behind
 protected void btnAutoRefresh_Click(object sender, EventArgs e)
 {
        //  code for Bind Grid

 }
  • It's bad technique to refresh page or part of it in interval. The point is to force clients update page by a signal from server only at specified time. –  Aug 01 '14 at 06:38
0

You need to use client notification technique, for example SignalR. You can read more about it here

Community
  • 1
  • 1