如何将类文件中的值传递给sitecore中的showModalDialogue?

时间:2013-12-21 01:33:12

标签: sitecore sitecore6

我为上下文菜单创建了以下代码。有一个模板,我创建了一个上下文菜单。当我点击上下文菜单时,它将获取字段值,并应显示在我已包含的ASPX文件中在这个代码中。我能够遍历项目中的字段,但无法传递给aspx文件。

using System; 
using System.Collections.Generic; 
using System.Linq;
using System.Web;

using Sitecore.Shell.Framework.Commands; using Sitecore.Web.UI.Sheer;
using Sitecore.Data.Items;

namespace ContextMenus
{
    public class CustomMenuType : Command
    {
        string ItemName;

        public override void Execute(CommandContext context)
        {
            if (context.Items.Length == 1)
            {
                Item _item = context.Items[0];
                System.Collections.Specialized.NameValueCollection _parameters = new System.Collections.Specialized.NameValueCollection();
                _parameters["id"] = _item.ID.ToString();

                Sitecore.Context.ClientPage.Start(this, "Run", _parameters);

                string ItemDatabase = _item.Database.Name;
                string ItemParent1 = _item.ID.ToString();

                Sitecore.Data.Database master1 = Sitecore.Configuration.Factory.GetDatabase(ItemDatabase);

                string ItemPath = _item.Parent.Paths.FullPath;

                Sitecore.Data.Items.Item home1 = master1.GetItem(ItemPath);
                ContextMenus.Entities.TemplateEntity objEntity = new ContextMenus.Entities.TemplateEntity();
                foreach (Sitecore.Data.Items.Item child in home1.Children)
                {
                    objEntity.Fname = child["First Name"];
                    objEntity.Lname = child["Last Name"];
                    objEntity.Dept = child["Department"];
                    objEntity.Age = child["Age"];
                }
            }
        }

        protected void Run(Sitecore.Web.UI.Sheer.ClientPipelineArgs args)
        {
            Sitecore.Text.UrlString _url = new Sitecore.Text.UrlString("/ContextMenus/CustomContextMenu.aspx");
            _url.Append("id", args.Parameters["id"]);
            Sitecore.Context.ClientPage.ClientResponse.ShowModalDialog(_url.ToString());
        }

        public override CommandState QueryState(CommandContext context)
        {
            foreach (Item _item in context.Items)
            {
                if (_item.TemplateID.ToString() != "{9F8334D3-01F3-4159-AA4A-BF513AC3E9FB}")
                {
                    return CommandState.Hidden;
                }
            }

            return base.QueryState(context);
        }
    }
}

我在代码后面编写了以下代码[CustomContextMenu.aspx.cs]。它只是从我的实体[TemplateEntity]获取数据,我想在aspx文件中显示它。

ContextMenus.Entities.TemplateEntity ObjTempEntity = new
ContextMenus.Entities.TemplateEntity();

StringBuilder sb = new StringBuilder();
sb.Append("First Name").Append("=").Append(ObjTempEntity.Fname);
Response.Write(sb.ToString());

StringBuilder sb1 = new StringBuilder();
sb1.Append("Last Name").Append("=").Append(ObjTempEntity.Lname);
Response.Write(sb1.ToString());

StringBuilder sb2 = new StringBuilder();
sb2.Append("Department Name").Append("=").Append(ObjTempEntity.Dept);
Response.Write(sb2.ToString());

StringBuilder sb3 = new StringBuilder();
sb3.Append("Age").Append("=").Append(ObjTempEntity.Age);
Response.Write(sb3.ToString());

我能够遍历Item字段值。我想在aspx文件中显示这些值。如何在showModalDialogue中传递带有值的字段名称。

1.我已经在queryState方法中对模板ID进行了硬编码。我在execute方法中获取该项的字段值。

2.我创建了CustomContextMenu aspx文件,我想显示字段值。如何将值从实体类[TemplateEntity]传输到CustomMenuType.aspx.cs文件。

1 个答案:

答案 0 :(得分:0)

调用Sitecore.Context.ClientPage.Start后,Execute方法中的所有内容似乎都是浪费精力。据我所知,它不会对任何事情产生任何影响。

您已将项目的ID传递给模式对话框。您应该能够使用Request.QueryString["id"]在对话框的代码隐藏中获取该ID。然后,您可以检索该项并获取其字段的值。