开发者

How do I use the Sitecore ShowControlPopup for dialog interactions with a user?

I've created a few simple commands based on what's in the Data Definition Cookbook where the user interaction is right click on an item -> insert -> MyCommand followed by a simple dialog box saying "Do you really want to do this". That's great.

Now I want a command that allows me to interact a bit more with the user at the dialog box. I need to add a couple of radio button lists so the user can select options and then a button to run the command. I think I need to use ShowControlPopup for this. I have created a control (ascx) to define what the popup will look like (and have published a test version to see that it works as a basic control in Sitecore). However, I am not sure exactly what the parameters to ShowControlPopup are.

The first paratered is called "Id" - What Id do I put in here? The id of an item that uses the popup control?

The second parameter is called "where" - I'm guessing this is the URL that the popup will have. Does a content item need to exist here or is it simply a dummy URL?

The third parameter is called "controlId" - What id do I put here? I have tried the id of my control that defines the popup but I get an error saying the control cannot be found.

When the user has chosen their options in the dialog box and clicks "ok" what handles the event? The Run method of the command class or an event handler in the codebehind for the popup control?

This is my code so far. If fails when it tries to create the control with an error about not being able to find the items with the id's supplied. I have just taken guesses at what items the popup control wants to know about.

protected void Run(Sitecore.Web.UI.Sheer.ClientPipelineArgs args)
{
 if (args.IsPostBack)
 {
  if (args.HasResult)
  { // normally code here would run when the dialog box is com开发者_如何学编程pleted by the user.  Is that so in this case?

  }
 }
 else
 {
  Sitecore.Context.ClientPage.ClientResponse.ShowControlPopup("F3684C4C-D9EF-4796-A471-5B05553119B6",
                 "http://mysite/dummy.aspx",
                 "B8D503D0-AEBE-43AE-B924-C3849F03E90D");

  args.WaitForPostBack();
 }
}

Cheers,

James.

Sitecore 6.2 rev 091012 / Win7 32bit / IIS7 / SQLExpress 2008 (local dev only)


Just for the record, Sitecore Support came back with some answers

1) "Id" is the ID of the item that is fires the popup

2) "Where" is a location relative to "Id". eg above, below, right-below

3) "controlId" is the ID of the item that is the popup

Examples from Sitecore that use ShowPopupControl are the main menu and context menu.

Also, the SheerUI is still undocumented and I was told to simply look for examples in the Sitecore code base. It is great that we can look at the Sitecore code, but a little direction would be great. Even if the doco simply said "For use of ShowPopupControl the UI example x can be found in class y in dll z".

The life of the command & popup can finish with the codebehind in the popup or with the command itself. This is dependant on the final args.WaitForPostBack() which can also be 'args.WaitForPostBack(true)or 'args.WaitForPostBack(false).

In the end I went with ShowModalDialog() because this was actually what I wanted rather than a popup that a user could click away from.

So my code ended up looking like this

protected void Run(Sitecore.Web.UI.Sheer.ClientPipelineArgs args)
{
    if (args.IsPostBack)
    {
        ;// we never come here becuase we have set waitforpostback to false.  all processing is handled by the popup control
    }
    else
    {
        Sitecore.Text.UrlString popUpUrl = new Sitecore.Text.UrlString("/sitecore/content/MYSITE/MyControlPageItem.aspx");
        popUpUrl.Append("id", args.Parameters["id"]);
        popUpUrl.Append("database", args.Parameters["database"]);
        popUpUrl.Append("language", args.Parameters["language"]);
        Sitecore.Context.ClientPage.ClientResponse.ShowModalDialog(popUpUrl.ToString(),"400", "600", "", true);

        args.WaitForPostBack(false);    // if this is true this command will wait for the modal dialog created above to close
                                        // at which time the Run method will check for postback & args
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜