Ciao a tutti,
ho deciso di registrarmi e chiedere a voi, perchè non so più dove battere la testa.
Ho creato un web user control così (mi perdonerete se la soluzione è rozza, ma non sono uno sviluppatore esperto proprio per niente):
<div>
<asp:CheckBox ID="wuc_cb_selection" runat="server" /><asp:Label ID="wuc_label_name" runat="server"></asp:Label>
<br />
<asp:HyperLink ID="wuc_hyperlink" runat="server"></asp:HyperLink>
<br />
<asp:Label ID="wuc_label_note" runat="server"></asp:Label>
</div> Ora devo utilizzarlo in modo programmatico, perchè deve essere ripetuto tante volte quanti sono gli elementi che mi ritorna un recordset. Per aggiungerlo alla pagina ho posizionato un placeholder e poi, da codice:
Dim wuc_moduleCustomCheckbox As Control = LoadControl("../controls/moduleCustomCheckbox.ascx")
Dim ucType As Type = wuc_moduleCustomCheckbox.GetType()
Dim ucPageHeadingProperty As PropertyInfo
wuc_moduleCustomCheckbox.ID = ds.Tables("modulesList").Rows(i)("IDMODULE")
ucPageHeadingProperty = ucType.GetProperty("cb_selection_checked")
ucPageHeadingProperty.SetValue(wuc_moduleCustomCheckbox, False, Nothing)
ucPageHeadingProperty = ucType.GetProperty("cb_selection_enabled")
ucPageHeadingProperty.SetValue(wuc_moduleCustomCheckbox, False, Nothing)
ucPageHeadingProperty = ucType.GetProperty("lb_name")
ucPageHeadingProperty.SetValue(wuc_moduleCustomCheckbox, ds.Tables("modulesList").Rows(i)("NAME"), Nothing)
ucPageHeadingProperty = ucType.GetProperty("lb_note")
ucPageHeadingProperty.SetValue(wuc_moduleCustomCheckbox, "note del modulo", Nothing)
ucPageHeadingProperty = ucType.GetProperty("lb_link")
ucPageHeadingProperty.SetValue(wuc_moduleCustomCheckbox, "http://www.google.com", Nothing)
ph_CheckboxModulesList.Controls.Add(wuc_moduleCustomCheckbox)
E sostanzialmente funziona.
Ora, io devo in fase di postback snocciolarmi tutti gli n control che ho creato programmaticamente per vedere se cb_selection_checked è selezionata, ed eventualmente eseguire del codice.
Non ho idea di come farlo.