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)
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
If you still have problem, Would you please show us with code sample so that we could reproduce your problem ?
Best regards
Cathy
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Thank you very much for the sharing of update panel information. I've tested but it's still not working to update the literal context text.
As per your request, I've shared the source code of both my custom control project (Control.Modal) and asp web project (Web.Modal) in my share folder with link.
Note: in the Web.Modal project, when button btnLaunchControlModal is click, it should change the content of the modal (which would be updated to literal in custom control). However it doesn't reflect although from debug walkthrough, the literal content text
is already updated.
None
0 Points
3 Posts
Trigger not working in updating UpdatePanel content in custom control
Jan 05, 2018 09:38 AM|bjlau|LINK
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: -
Private upPnl As UpdatePanel
Private litHTML As Literal
upPnl = New UpdatePanel
upPnl.ID = "upPnl"
upPnl.UpdateMode = UpdatePanelUpdateMode.Conditional
litHTML = New Literal
litHTML.ID = "litHTML"
upPnl.ContentTemplateContainer.Controls.Add(litHTML)
*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
Me.Controls.Add(upPnl)
<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
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()
*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
Star
8670 Points
2882 Posts
Re: Trigger not working in updating UpdatePanel content in custom control
Jan 08, 2018 07:33 AM|Cathy Zou|LINK
Hi bjlau
You could check the link below first:
http://www.c-sharpcorner.com/UploadFile/4088a7/understanding-update-panels-with-triggers-and-custom-control/
If you still have problem, Would you please show us with code sample so that we could reproduce your problem ?
Best regards
Cathy
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
None
0 Points
3 Posts
Re: Trigger not working in updating UpdatePanel content in custom control
Jan 08, 2018 11:54 PM|bjlau|LINK
Dear Cathy,
Thank you very much for the sharing of update panel information. I've tested but it's still not working to update the literal context text.
As per your request, I've shared the source code of both my custom control project (Control.Modal) and asp web project (Web.Modal) in my share folder with link.
https://drive.google.com/drive/folders/13fkDIa2G5pF7XmVbuGH---bPnQjWj33P?usp=sharing
Note: in the Web.Modal project, when button btnLaunchControlModal is click, it should change the content of the modal (which would be updated to literal in custom control). However it doesn't reflect although from debug walkthrough, the literal content text is already updated.
Best Regards,
Beejay
None
0 Points
3 Posts
Re: Trigger not working in updating UpdatePanel content in custom control
Jan 14, 2018 05:52 AM|bjlau|LINK
I've been cracking my head but still not able to get it work.
Is anyone out there able to share some tips on how to get about with this issue?
I've included the source code in google drive for what i've done so far.
Appreciate a lot for helps
Thank you