Note that there are some explanatory texts on larger screens.

plurals
  1. POInteraction between two user controls
    primarykey
    data
    text
    <p>I'm on the verge of madness ...</p> <p>In the application I'm actually building, I'm dealing with two dynamically-added controls that need to interact with each other, but I've reduced the problem to an as-simple-as-I-can-make-it example with the controls being statically loaded, and it still presents the same problem: a NullReferenceException when invoking the delegate. Here's the gist:</p> <p><strong>Control 1</strong></p> <pre><code>Partial Class Control1 Inherits System.Web.UI.UserControl Private _delClicked As System.Delegate Public WriteOnly Property UpdateLabel() As System.Delegate Set(ByVal value As System.Delegate) _delClicked = value End Set End Property Protected Sub btnButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnButton.Click Dim aObj(0) As Object aObj(0) = 1 _delClicked.DynamicInvoke(aObj) End Sub End Class </code></pre> <p><strong>Control 2</strong></p> <pre><code>Partial Class Control2 Inherits System.Web.UI.UserControl Protected WithEvents Control1 As New Control1 Delegate Sub ChangeLabel(ByVal int As Integer) Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init Dim delChangeLabel As New ChangeLabel(AddressOf UpdateLabel) Me.Control1.UpdateLabel = delChangeLabel End Sub Private Sub UpdateLabel(ByVal int As Integer) lblLabel.Text = "Value is now " &amp; int End Sub End Class </code></pre> <p>If I put a breakpoint on the line of Control2 where the Control1 delegate is assigned, I can step through and watch it get set in the Control1 object. However, when the btnButton_Click event fires, the value of _delClicked has gone back to Nothing.</p> <p>Any help would be greatly appreciated. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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