Updating content block from user control - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Updating content block from user control

  • Updating content block from user control
  • Hi,

    on a page I have several content blocks and a user control. The displayed data in the content blocks depends on the context and should be updated "on the fly" programatically by the user control code.

    Could you please help me to figure out how to do that ?

    Thank you.

    Francois
  • Hello Francois,

    Use a single control or QueryString to pass data between controls.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  • Because of the layout of the page, I cannot use a single control.

    Using QueryString is pretty unconvenient for 2 reasons:
        - 1°) I couldn't use a standard content block, but I would have to replace it with another user control. It's easy but seems kind of a "heavy" and non practical solution to me
        - 2°) In that case I would have to force a second post back to have the second user control deal with the query string (or session variable)

    So I reformulate my question: is there an elegant solution for a user control serverside code to update content blocks on the current page (understanding that sutch content is volatile and will be displayed but not saved) ?

    Thanks for your help.
    Francois
  • Hello Francois,

    You can use session to persist some data and then reuse it. We have some issues with the session that will be sorted out in the next internal weekly build.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  • "...and then reuse it..."

    This is precisley what I would like to avoid! Because reusing means re-posting; which I do not want. I don't wish to persist data, but to update a control block from a user control.

    Therefore I go again with the same question:

    Is it possible for a user control serverside code to update content blocks on the current page, yes or no ? If it is possible, could you please tell me how ?
    If it is not possible, could you please tell me why?
  • 238264_changeValue.zip
    Hello Francois,

    1. It is possible to set the value at runtime, but you need to implement a function that will recursively loop through the page controls collection and find the control you are looking for. Generally even adding one control on a page - ContentBlock in will not be on the first level of page controls. The control is inside a LayoyoutControl.

    sample

    void changeValue_Click(object sender, EventArgs e)
        
            var c = ((Telerik.Sitefinity.Modules.GenericContent.Web.UI.ContentBlock)((((((this.Page.Controls[3]).Controls[2].Controls[0]).Controls[3]).Controls[1]).Controls[1]).Controls[0]));
            c.Html = TextToChange.Text;
        

    I attached a short video.

    2. The better option here is using one control as suggested.


    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.