+1-888-365-2779
Try Now
More in this section

Forums / Sitefinity SDK / Updating content block from user control

Updating content block from user control

6 posts, 1 answered
  1. Francois MARTIN
    Francois MARTIN avatar
    29 posts
    Registered:
    07 Aug 2005
    16 Dec 2010
    Link to this post
    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
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    16 Dec 2010
    Link to this post
    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.
  3. Francois MARTIN
    Francois MARTIN avatar
    29 posts
    Registered:
    07 Aug 2005
    16 Dec 2010
    Link to this post
    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
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    16 Dec 2010
    Link to this post
    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.
  5. Francois MARTIN
    Francois MARTIN avatar
    29 posts
    Registered:
    07 Aug 2005
    16 Dec 2010
    Link to this post
    "...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?
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Dec 2010
    Link to this post
    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.
    Answered
6 posts, 1 answered