Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing the property inside Dynamic control gives Null reference exception
    primarykey
    data
    text
    <p>I have an app with 24 different Forms. They have some security options based on which the 5 different buttons Submit, Approve, 2nd Approve, 3rd Approve, Reject etc get enabled disabled.</p> <p>Now I designed a MainForm that has all the buttons and the security code for them. I have created eachform as a usercontrol and load them dynamically based on which form the user wants. My loading works perfectly fine. I load the control and Add it to the place holder in the Page load event of the main page. </p> <p>Now when the user selects the Submit button I want to call the Save method inside the usercontrol of the Form as each form will have a separate Save. So when I try this code snippet I get the Null reference error. Do let me know how to resolve it. </p> <pre><code>Private UCDynamic As UserControl </code></pre> <p>Then on Page Load event I use this code</p> <pre><code>Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If not Me.IsPostBack UCDynamic = LoadControl("Controls/BkCode.ascx") Me.PlaceHolderForm.Controls.Add(UCDynamic) End if </code></pre> <p>Then on the ButtonClick Event for Submit I do this</p> <pre><code> Protected Sub Save_OnClick(ByVal sender As Object, ByVal e As EventArgs) Save() End Sub Sub Save() CType(Me.UCDynamic, controls_BkCode).Save() End Sub </code></pre> <p>Thats where I get the cast Null reference error. So is it that after post back the control no longer exist on the page. Any ideas will be greatly appreciated.</p> <p>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.
    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