January 4, 2011

Interact with the user in the admin forms

In the XAML forms, you may interact with the user with these kind of method

Display a popup:
Sitecore.Context.ClientPage.ClientResponse.Alert("My message");

Download a file
Sitecore.Context.ClientPage.ClientResponse.Download(@"c:\MyPath\Myfile.xxx");

Display an input
Input(string text, string defaultValue, string validation, string validationText, int maxLength)

Change the HTML in ajax:
SheerResponse.SetInnerHtml("MyBorderName", "My String");

Launch a timer (to refresh the page every XX seconds for example)
SheerResponse.Timer("CheckStatus", 100);

If you inherit from WizardFrom these methods work perfectly, but if you inherit from Sitecore.Web.UI.Sheer.BaseForm it seem that it doesn't work.
Here is a simple workaround to bypass this limitation:
  • Add this in you xaml:

    <script type='text/javascript'>window.setTimeout('scForm.invoke("local:show")', 0)</script>
    
  • And now you can invoke these methods without problems

    [HandleMessage("local:show")]
    protected void Show(Message message)
    {
        //This method work to launch a timer
        SheerResponse.Timer("CheckStatus", 100);            
    }
    

No comments:

Post a Comment