locked
Calling a vb method using updatepanel RRS feed

  • Question

  • User1239610449 posted

    I have method in my code behind, that method used to collect geo-coordinates from database and plot them on google map on my webpage.

    I want to call that method after every 60 seconds using updatepanel so that only the latest coordinates should be collected and plot them on map accordingly without refresh the map.

    How can I invoke that method using updatepanel. Please help.

    Thursday, September 27, 2018 6:44 PM

Answers

  • User-893317190 posted

    Hi knowledgist,

    Do your changes need to run javascript code?

    If so , you need to register a  javascript code to run after the  response returns.

    Below is my code.

       <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            
            <asp:UpdatePanel ID="UpdatePanel1" runat="server"
               
                >
    
                <ContentTemplate>
                     <asp:Timer runat="server" OnTick="timer1_Tick" Interval="2000"  ID="timer1" ></asp:Timer>
                      <asp:Label runat="server" Text="Label1" ID="Label1"></asp:Label>
                </ContentTemplate>
              
    
            </asp:UpdatePanel>
            <script>
               
                function callback() {
                    alert("callback")
                }
            </script>

    Code behind.

    You could register javascriopt code through ScriptManager.RegsterStartupScript method.The third parameter is the name of your script, the fourth parameter is the javascript code you want to run after the response returns. The last parameter means you want to wrap the code with <script></script>.

     Protected Sub timer1_Tick(sender As Object, e As EventArgs)
            Label1.Text = DateTime.Now.ToString()
            ScriptManager.RegisterStartupScript(Me, Me.GetType(), "callback", "callback()", True)
        End Sub

    The result.

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 28, 2018 7:49 AM

All replies

  • User-893317190 posted

    Hi knowledgist,

    You could combine updatepanel with timer to help you.

    Below is my code. Please put the control which you want to change in your code behind in the updatepanel's ContentTemplate or it won't work. Interval="2000" represents two seconds.

     <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
            <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
            <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
            <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
            <asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server"
               
                >
    
                <ContentTemplate>
                     <asp:Timer runat="server" OnTick="timer1_Tick" Interval="2000"  ID="timer1" ></asp:Timer>
                      <asp:Label runat="server" Text="Label1" ID="Label1"></asp:Label>
                </ContentTemplate>
              
    
            </asp:UpdatePanel>
    
        </form>

    And my code behind. I change the time of Label1 every two seconds.

      Protected Sub timer1_Tick(sender As Object, e As EventArgs)
            Label1.Text = DateTime.Now.ToString()
        End Sub

    The result. As you could see, the response only contains content in the updatepanel.

    Best regards,

    Ackerly Xu

    Friday, September 28, 2018 2:29 AM
  • User1239610449 posted

    Hi Ackerly,

    Thanks for you reply. As you instructed, I did it and it is working fine (the vb method is invoking and collecting the latest coordinates from DB) but I want those geo-coordinates to put on google map and the script code is not refreshing so I am not able to see the changes on map.

    Stuck up!

    Friday, September 28, 2018 7:12 AM
  • User-893317190 posted

    Hi knowledgist,

    Do your changes need to run javascript code?

    If so , you need to register a  javascript code to run after the  response returns.

    Below is my code.

       <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            
            <asp:UpdatePanel ID="UpdatePanel1" runat="server"
               
                >
    
                <ContentTemplate>
                     <asp:Timer runat="server" OnTick="timer1_Tick" Interval="2000"  ID="timer1" ></asp:Timer>
                      <asp:Label runat="server" Text="Label1" ID="Label1"></asp:Label>
                </ContentTemplate>
              
    
            </asp:UpdatePanel>
            <script>
               
                function callback() {
                    alert("callback")
                }
            </script>

    Code behind.

    You could register javascriopt code through ScriptManager.RegsterStartupScript method.The third parameter is the name of your script, the fourth parameter is the javascript code you want to run after the response returns. The last parameter means you want to wrap the code with <script></script>.

     Protected Sub timer1_Tick(sender As Object, e As EventArgs)
            Label1.Text = DateTime.Now.ToString()
            ScriptManager.RegisterStartupScript(Me, Me.GetType(), "callback", "callback()", True)
        End Sub

    The result.

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 28, 2018 7:49 AM
  • User1239610449 posted

    Ok, It is now perfectly done, But can not we refresh this map asynchronously ?

    Friday, September 28, 2018 7:54 AM
  • User-893317190 posted

    Hi knowledgist,

    I don't understand what you mean by refresh this map asynchronously.

    If you talk about this way of call js. It  is an ajax call , just as you use  $.ajax and write you code in success function.

    Best regards,

    Ackerly Xu

    Friday, September 28, 2018 8:11 AM