Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Trigger not working in updating UpdatePanel content in custom control

$
0
0

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: -

  1. declare UpdatePanel and Literal control in my custom control
    Private upPnl As UpdatePanel
    Private litHTML As Literal
  2. initialize the UpdatePanel and Literal (in Sub CreateChildControls())
    upPnl = New UpdatePanel
    upPnl.ID = "upPnl"
    upPnl.UpdateMode = UpdatePanelUpdateMode.Conditional

    litHTML = New Literal
    litHTML.ID = "litHTML"
  3. assign Literal as control to UpdatePanel
    upPnl.ContentTemplateContainer.Controls.Add(litHTML)
  4. 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
  5. Add control to the custom control unit (in Sub CreateChildControls())
    Me.Controls.Add(upPnl)
  6. 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
  7. 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()
  8. 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


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>