Hi,
I have a custom control which have an updatepanel in it. In this updatepanel, it only have a literal control which would be used to dynamically generate html code. The trigger control (from page) is assigned to updatepanel on Sub CreateChildControls dynamically. However when the control is fired (for my case is button click), the literal content in the updatepanel is not updated. I've tested various way (some is rather stupid) but to no avail. Hope I would be able to reach some light thru this forum. Thanks in advances. Below is the code for my custom control and page: -
- declare UpdatePanel and Literal control in my custom control
Private upPnl As UpdatePanel
Private litHTML As Literal - initialize the UpdatePanel and Literal (in Sub CreateChildControls())
upPnl = New UpdatePanel
upPnl.ID = "upPnl"
upPnl.UpdateMode = UpdatePanelUpdateMode.Conditional
litHTML = New Literal
litHTML.ID = "litHTML" - assign Literal as control to UpdatePanel
upPnl.ContentTemplateContainer.Controls.Add(litHTML) - dynamically assign trigger to UpdatePanel (in Sub CreateChildControls())
*Note: The trigger control ID from page is stored in Hashtable and assign in page code behind (refer to item 8)
If Not AsyncPostBackTriggerControlID Is Nothing Then
For Each Entry As DictionaryEntry In AsyncPostBackTriggerControlID
Dim asynDynamic As New AsyncPostBackTrigger
asynDynamic.ControlID = Entry.Key.ToString
upPnl.Triggers.Add(asynDynamic)
Next
End If - Add control to the custom control unit (in Sub CreateChildControls())
Me.Controls.Add(upPnl) - Property in custom control to allow assignment of trigger from page
<Bindable(True), Category("Trigger Configuration"), DefaultValue(""), Description("The collection of control ID to be added as trigger for asynchronous postback trigger."), Localizable(True)>
Public Overridable Property AsyncPostBackTriggerControlID() As Hashtable
Get
Return CType(ViewState("AsyncPostBackTriggerControlID"), Hashtable)
End Get
Set(ByVal value As Hashtable)
ViewState("AsyncPostBackTriggerControlID") = value
End Set
End Property - Code in my render
Dim upPnlID As New StringBuilder(Me.ClientID)
upPnlID.Append("_")
upPnlID.Append(upPnl.ID)
writer.AddAttribute(HtmlTextWriterAttribute.Id, upPnlID.ToString)
writer.RenderBeginTag(HtmlTextWriterTag.Div)
litHTML.RenderControl(writer)
writer.RenderEndTag() - Code behind in Page (in Sub Page_Load)
*Note: CstCtrl is the control ID for the custom control use in page
Dim ht as New Hashtable
ht.Add(btnTrigger.ClientID, True)
CstCtrl.AsyncPostBackTriggerControlID = ht
Thanks