Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.Net - Update controls inside an Update Panel when raising an event
    text
    copied!<p>ASP.Net noob here trying to update a control inside an UpdatePanel inside a method subscribing to an event, with no luck.</p> <p>Some background, I have written a DLL that interfaces with a standard POTS telephone and I have mapped various occurences on the phone end (phone being picked up, phone ringing etc) to .Net events.</p> <p>In my ASP.Net solution, I have added my DLL, instantiated my phone and, in methods subscribing to my events I want to update various labels inside an UpdatePanel with information inside the EventArgs objects being passed into my methods.</p> <p>Using breakpoints, I can see that my Phone object is functioning as expected, the events are being raised when they are supposed to and the EventArgs contain the information they are supposed to.</p> <p>But the labels inside the UpdatePanel never update. I wrote the previous version of the application as a Windows Form, and I recall that whenever updating the UI from another thread, I had to check whether <code>InvokeRequired</code> was true first, and if so call the <code>Invoke</code> method but I don't know what the equivalent to this is in ASP.Net (if there is one).</p> <p>Markup is below (this is just an example project I have created to get my head around the basics):</p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;style type="text/css"&gt; #form1 { text-align: center; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt; &lt;/asp:ScriptManager&gt; &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"&gt; &lt;ContentTemplate&gt; &lt;asp:Label ID="Label1" runat="server" style="text-align: center" Text="Label"&gt;&lt;/asp:Label&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:Button ID="Button1" runat="server" Text="Button" /&gt; &lt;/ContentTemplate&gt; &lt;Triggers&gt; &lt;asp:AsyncPostBackTrigger ControlID="ScriptManager1" EventName="Load" /&gt; &lt;/Triggers&gt; &lt;/asp:UpdatePanel&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Now for the code:</p> <pre><code>using System; //My DLL using Maximiser; namespace WebApplication2 { public partial class WebForm1 : System.Web.UI.Page { //My Phone Object private Phone _ThisPhone { get; set; } protected void Page_Load(object sender, EventArgs e) { //Instantiating Phone Object with IP Address and Port _ThisPhone = new Phone("8.8.8.8", 8888); //Hookstate event indicates phone is off/on the hook _ThisPhone.HookState += new EventHandler&lt;Maximiser.Events.Hookstate&gt;(thisPhone_HookState); } void thisPhone_HookState(object sender, Maximiser.Events.Hookstate e) { //I want to update my Label with the phones current HookState Label1.Text = e.State; //Now I want to refresh the UpdatePanel but not reload the page UpdatePanel1.Update(); } } } </code></pre> <p>The method is definitely running as shown below:</p> <p><img src="https://i.stack.imgur.com/5eUt7.jpg" alt="Breakpoint"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload