Can I retrieve an item that was added via the Page Editor in the codebehind of my page? (Sitecore, C#)

79 Views Asked by At

I'm new to Sitecore and in the codebehind of my page, I'm setting values for Google analytics based on the information that I have for a previously designed page (I can't change the basic structure of these pages). Most of the fields I need are set in Sitecore in the Content Editor, so I can access them via

Sitecore.Content.Item.Fields["fieldname"]

However, one thing I need is the URL of the logo image on each page, which is inserted with the Page Editor. Is it possible for me to get Page Editor objects on the page in the codebehind?

3

There are 3 best solutions below

0
Clint B On

I'm assuming by Page Editor you mean the Design view. If so, click the Source button to view the markup and find the control that contains the URL. Give that control a unique ID and make sure it has the runat="server" attribute. After that, you will be able to access that control in the code behind by using Me.<uniqueID>.

0
Anton On

No, Page Editor (Experience Editor) works with JavaScript to change anything on page. Then changes that were made on page are transferred to server and applied there, but it is not relate to codebehind of your page at all. It is all is done by custom Sitecore pipelines. However after applying changes(Save button) you'll be able to access to changed field via your codebehind on page reload.

So, you have two options:

  1. Patch Sitecore "SaveUI" pipeline and add processor to it to get changes, and do something with them.
  2. Wait after changes are applied, page will be reloaded and you will be able to access changed field in your codebehind
0
sharpslinger On

Google Analytics is client-side; consider using client-side script to retrieve the value of the logo URL. To do that, your script will need to execute after the page has loaded.

If you're using jQuery, you could do something like this

jQuery(document).ready(){
    var logoUrl = jQuery('.logo').attr("src");
}