Dealing with multiple iFrame fields

The iFrame field type allows you to create your own GUI for a particular sitecore field. You create a UserControl and reference it with your iFrame field.

Good so far! By default, Sitecore will pass some parameters to your UserControl page (taken right from the sitecore documentation):

  • id – The GUID of the item selected by the user.
  • la – The language code selected by the user.
  • vs – The version number selected by the user.

Super! What if i have multiple iFrame fields on my item that point to the same UserControl though? What’s missing? How about what field am I supposed to be loading from.

This isn’t really a big deal though because the iFrame field type also allows you to specify extra parameters when you set the URL to your UserControl in the field data source. I pass an extra “?field=my-field-name” parameter to the end of my iFrame data source when necessary to avoid this issue. Then in the Page_Load of my UserControl I can use it like so:


if (!IsPostBack)
{
Database db = Factory.GetDatabase("master");
Item myItem = db.GetItem(Request.Params["id"]);
string fieldvalue = myItem[Request.Params["field"]];

// ...
// code to load my control with "fieldvalue"
// ...

}

About Paul Martin

I enjoy rock climbing, playing guitar, writing code...
This entry was posted in Drexel, Field Types, Sitecore. Bookmark the permalink.

One Response to Dealing with multiple iFrame fields

  1. Vipul says:

    This is the great help. It worked for me.
    Thanks a lot Paul.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s