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

Forums / Developing with Sitefinity / Replacing Items from database in Generic Content

Replacing Items from database in Generic Content

6 posts, 0 answered
  1. TIOS
    TIOS avatar
    48 posts
    Registered:
    22 Mar 2006
    11 Nov 2009
    Link to this post
    Got an interesting one here.

    We've got a user control currently getting information from the database for example:

     

    <div id="white">

     

     

    <div id="mainContent">

     

     

    <div class="headlines">

     

     

    <h2>Classic &amp; Vintage Cars &amp; Motorcycles</h2>

     

     

    <uc:CurrentSaleDate ID="sd" runat="server" DepartmentFilter="CDF14B3B-5714-43A2-9C5E-105DC0EFC8AB" Template="<h3>{SaleDate}</h3>" />

     

     

    </div>

     

     

    </div>
    loads of html cut here

     

    </div>

    So once approach to this would be cut the html and put a Generic Content at the top then the custom control, then another Generic Content control.  But because the ending div's follow you can imagine what the Editor likes doing (closing the divs etc).

    In an ideal world i've got a common set of things I need for example {CurrentSaleDate}, {CurrentSaleTime}, {CurrentSaleTitle}, {CurrentSaleDescription}, etc.  If I could put normal html in the generic content item and where a call is needed just put {CurrentSaleDate}, etc. then get the master page to set the default departmentfilter id and then replace any database items on the fly everytime someone visits the page (as it can't save the latest CurrentSaleDate, etc back to the database).

    Has anybody got ideas or sample code how to archive this?

    Thanks.
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    12 Nov 2009
    Link to this post
    Hi Chris Bond,

    If I should be honest, I am not sure how the things work and what is the target goal. I apologize for that, but could you please elaborate a bit more?

    Wherever you place the Generic Content control on the user control, the RadEditor will take care only about the html which is in the editor's iframe, it will not touch the rest of the html. If you want to place the markers in the generic content text ({SaleDate}, etc), then you can add a code behind to the user control and try to get the text, then perform search & replace.

    Still, if you could elaborate a bit more, it will be great. 

    Sincerely yours,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. TIOS
    TIOS avatar
    48 posts
    Registered:
    22 Mar 2006
    12 Nov 2009
    Link to this post
    Thanks for the reply - I know what i want in my head just hard getting it down on paper!

    Effectively what im after is a user control inside a generic content item.  At the moment we know that's not possible so this was my attempt of a workaround so to speak.

    Take for example a Current Sale Date, i'd like to insert it dynamically in the generic content so currently  it says "The sale is on Tuesday, 24th November 2009", currently this format is static and requires user intervention.  We have all this information in the database including which is the current sale and each department have there own master page template setup.

    So my idea was instead of putting in "The sale is on Tuesday, 24th November 2009", the user would enter "The sale is on {SaleDate}".  The apart i'm struggling with how to successfully implement searching the Generic Content item on the page being rendered and replacing it with the relivant information.  This probably would need to be done on the master page i'd say......

    Does this make more sense?

    Thanks,
    Chris
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    12 Nov 2009
    Link to this post
    Hello Chris Bond,

    You can try using jQuery. Then when you input content in the generic content module you will Apply a CSS Class to the SaleDate text. This will surround the text with <span> tags that have class property set to the class you have selected. Now you need to add some jQuery functions to find the span with the class that you have assigned and change its value.

    Best wishes,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. TIOS
    TIOS avatar
    48 posts
    Registered:
    22 Mar 2006
    12 Nov 2009
    Link to this post
    Do you have any sample code for this as the sale date information is all in SQL Server, never accessed anything from there using jquery yet!

    Thanks,
    Chris
  6. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    12 Nov 2009
    Link to this post
    Hi Chris Bond,

    Well you do not have to. You will wrap the jQuery logic in a user control. This user control will have a non visible filed which will hold sale data accessed through server methods (for example on page load). Then you will add this user control to your template. Or you can do this directly on the master page (without user control) but with the same logic.

    The other available method would be to use javascript calls to a WCF web service that will call a server method to get the data from SQL server and then pass it on the client. I think first approach is easier.

    I hope that this will clear things up.

    Greetings,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
6 posts, 0 answered