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

Forums / Developing with Sitefinity / How to add custom property while creating page

How to add custom property while creating page

23 posts, 0 answered
  1. Dinesh
    Dinesh avatar
    46 posts
    Registered:
    03 Aug 2009
    03 Aug 2009
    Link to this post
    Hi,

    My site is having a top navigation(Site Menu),tab strip(Site TabStrip) and right navigation(Site Panelbar). Some of the sub pages in the top nav is show in tab strip. The remaining sub pages is displayed in right nav. some times a single web page is displayed in both tab strip and right navigation.
    So, I wanna proceed in the following way:
    1. Modified the 'PagePropertiesInsert.ascx' file and added a field 'Show in right Nav'
    2. Insert the value in the database
    3. Iterate through all the pages and based on the value, display the appropriate page in the right navigation

    I added the field 'Show in right Nav' similar to 'Show in Navigation' field as shown in the url below.
    http://img300.imageshack.us/i/createpage.jpg/
    Now how to insert this data into the database as I couldn't find the event for the submit button 'Create this page'.

    Can we get my requirement in doing so? or any other way to implement this???
    Could anyone give me a possible solution for this....

    -Thanks
      Dinesh
  2. Dinesh
    Dinesh avatar
    46 posts
    Registered:
    03 Aug 2009
    03 Aug 2009
    Link to this post
    I have added the custom field in the following way:

    <add key="Pages.Subtitle" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue=""/>

    Then, in the folder ~/YourProject/Sitefinity/Admin/ControlTemplates/Pages, goto PagePropertiesEdit.ascx and PagePropertiesInsert.ascx files and added the following

    <asp:Label ID="Label8" AssociatedControlID="Subtitle" Text="Subtitle" runat="server"></asp:Label>
    <asp:TextBox ID="Subtitle" Text="" runat="server"></asp:TextBox>


    Now I can see the custom field while editing and creating pages. But, I am unable to save the data.

    Does sitefinity takes care of creating a field in database or do we need to create a field in database and custom code to save that info?


    -Dinesh
  3. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    03 Aug 2009
    Link to this post
    Hello Dinesh Kumar,

    Thank you for using our services.

    In regards with what you want to achieve I can point you to a blog post by one of our partners (Habañero). In the blog post (Page Meta Data - Intercepting Sitefinity) they discuss their implementation of custom meta data for pages. Please have a look at it and see if it will help you.

    If you have more questions, please feel free to contact us.

    Regards,
    Rado
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
  4. Dinesh
    Dinesh avatar
    46 posts
    Registered:
    03 Aug 2009
    05 Aug 2009
    Link to this post
    Hi,

    I have followed the above link and everything went fine.
    I have created a field in PagePropertiesEdit.ascx.
    For the first time if we click on view properties then the field should be populated with the value present in the database. After any modifications to the field and click save button, those changes will be saved into the database.

    The problem here is, I implemented some code in the page load event of PagePropertiesEdit.ascx.cs
     protected void Page_Load(object sender, EventArgs e) 
        { 
             
            if (!IsPostBack) 
            { 
               do something 
            } 
             
             
        } 


    and some code in the button click of SAVE.
    But, everytime the page POSTBACK property is showing true.

    Why is this happening so???
    I want to implement that code only if the page is not PostBack. How can I achieve this??

    -Thanks
     Dinesh
  5. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    10 Aug 2009
    Link to this post
    Hello Dinesh Kumar,

    You are right, the property is always true. The reason for this is that Sitefinity is actually doing a postback with the every new navigation. There are reasons for that, but this will be changed in Sitefinity 4.0.

    For the time being, you can use a boolean flag for example. Once you pass the code set true to this flag, so on the next reload you know that something happened already.

    Sincerely yours,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
  6. Dinesh
    Dinesh avatar
    46 posts
    Registered:
    03 Aug 2009
    10 Aug 2009
    Link to this post
    Hi Georgi

    Thanks for your reply...

    There is a problem if we use the flag.
    Since the bool value is false by default, I can execute the code for the first time and set the value to True at the end of the code. Also, at the end of button click event I reset the value of the flag. This workd fine If I view the properties and save them.

    Now I view the properties but, I didn't Click on Save button and Clicked on another page. Now the code won't execute because the flag is set to true.  Here, the logic fails.

    Is there any other way to implement this?


    -Dinesh
  7. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    13 Aug 2009
    Link to this post
    Hello Dinesh,

    Perhaps you can use the Control State, or the view state to save the flags which will be used in the control initialization.

    Greetings,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
  8. Dinesh
    Dinesh avatar
    46 posts
    Registered:
    03 Aug 2009
    14 Aug 2009
    Link to this post
    Thanks for the reply Georgi...

    I have disabled the view state and still no luck. I don't have a good idea on Control state.
    Could you suggest me on how to use the Control state?

    -Dinesh
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    15 Aug 2009
    Link to this post
    Hi Dinesh,

    You can take a look at the following literature which describes Control and View states.

    Understanding ASP.NET View State
    Control State vs. View State Example

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  10. Gokhan
    Gokhan avatar
    32 posts
    Registered:
    11 Jul 2008
    09 Sep 2009
    Link to this post
    hi Dinesh
    Can you update the thread pls as i am having same issue ? ControlState or Viewstate solved this issue or you have found another solution?
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    09 Sep 2009
    Link to this post
    Hello Gokhan,

    You can take a look at the provided links and at Habanero's page listed above. Also you may find the following post useful - Adding_Properties_to_Sitefinity_Pages which shows more simple implementation. Currently the only option to add  page properties is to hack the InternalPage or create some custom properties that you persist in different tables. Managing page properties will be available form Sitefinity 4.0.

    Regards,
    Ivan Dimitrov
    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.
  12. Gokhan
    Gokhan avatar
    32 posts
    Registered:
    11 Jul 2008
    09 Sep 2009
    Link to this post
    Hi Ivan;

    Actually Waiting for 4.0 version or Gabe's "Adding_Properties_to_Sitefinity_Pages" implementation are not the right answers for me. I hacked the DB and implemented my fields. It is working fine but As Dinesh declared before i need to catch "isPostBack" properties works properly on "PagePropertiesEdit.ascx.cs".ViewState is not a solution , dont know how ControlState can solve my problem .If Dinesh solved  this issue , i would love to know 
  13. Dinesh
    Dinesh avatar
    46 posts
    Registered:
    03 Aug 2009
    12 Sep 2009
    Link to this post
    Hi Gokhan,

    I apologize for my delay in response.
    I changed my implementation of using custom properties as this postback issue is not solved in 3.6 version.
    Rather I created a page group which consists of the pages I need to show only at my right navigation and a custom datasource to get all the pages in page group and bind them even the ShowInNavigation property is set to false. 

    Does this helps you? If not, can you write what would you like to implement using custom properties. I will try to provide some help.

    -Dinesh
  14. Gokhan
    Gokhan avatar
    32 posts
    Registered:
    11 Jul 2008
    15 Sep 2009
    Link to this post
    Hi Dinesh;

    Thank you a lot for yor assistance ,it was helpful. I managed to sort it out . Have a lovely day..
  15. Ivan
    Ivan avatar
    51 posts
    Registered:
    22 Aug 2007
    24 May 2010
    Link to this post
    Hi Ivan,

    The link to Hack: Adding Properties to Sitefinity Pages no longer seems valid.  Is there another location where I can view this article?  Are there any newer solutions to adding custom metadata fields to pages in Sitefinity 3.7 SP3?

    Thanks.
    -Ivan
  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 May 2010
    Link to this post
    Hi Ivan,

    There is a  blog post written by one of our partners (Habañero). In the blog post (Intercepting Sitefinity) they discuss the way how to implement custom metadata for pages.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  17. Jay
    Jay avatar
    51 posts
    Registered:
    16 Jul 2008
    26 May 2010
    Link to this post
    I was looking for similar info.  The link to Gabe's blog appears to have changed.  If anyone's looking for it, it's:

    http://www.sitefinitywatch.com/blog/09-03-12/Hack_Adding_Properties_to_Sitefinity_Pages.aspx
  18. Ivan
    Ivan avatar
    51 posts
    Registered:
    22 Aug 2007
    26 May 2010
    Link to this post
    Thanks Jay!  This gives me another potential solution.

    Regards.
    -Ivan
  19. Jason Hedges
    Jason Hedges avatar
    22 posts
    Registered:
    16 Jul 2009
    04 Feb 2011
    Link to this post
    The link you provided to Habanero's blog post is no longer valid. Can you provide that information or a new link please?

    Thanks!
  20. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    08 Feb 2011
    Link to this post
    Hi Jay,

    It looks like they removed the post from the site. You might find these posts useful

     

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  21. alexer
    alexer avatar
    1 posts
    Registered:
    25 Mar 2011
    25 Mar 2011
    Link to this post

    I add a custom property to a WMi Object's Property Collection using the following code.

    foreach (ManagementObject WebSite in WebSitesCollection)
            {
                if (WebSite.Properties["Name"].Value.ToString().Contains(appPoolName))
                {
                    foreach (PropertyData propertyData in WebSite.Properties)
                    {
                        try
                        {

                            HttpContext.Current.Response.Write(propertyData.Name + "  " + propertyData.Value + "<br/>");
                            if (propertyData.Name.Equals("Enable32BitAppOnWin64"))
                            {
                                AppPoolx.SetPropertyValue("Enable32BitAppOnWin64", true);
                                AppPoolx.Put(); return true;
                            }
                            else
                            {
                             AppPoolx.Properties.Add("Enable32BitAppOnWin64", true);
                              AppPoolx.Put(); return true;
                            }

                        }
                        catch (Exception ex1)
                        {
                            HttpContext.Current.Response.Write("Error Ocurred while Setting Property: " + ex1.Message + "<br />");
                            break;
                        }
                    }
                }

            }

     

  22. Naveen
    Naveen avatar
    9 posts
    Registered:
    25 Jul 2011
    18 Oct 2011
    Link to this post
    How do i do it in sitefinity 4.2?
  23. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    18 Oct 2011
    Link to this post
    Hi Naveen,

    In 4.x you can have custom properties using GetValue and SetValue DataExtenssion methods of the PageNode object, but the service would not persist them. You can do this programmatically by subscribing in Global.asax for Executed or Executing events of the PageManager.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
23 posts, 0 answered