Sitecore Core Development

Wednesday, October 05, 2005

Showing a modal dialog on load

When a form loads, Sheer UI post-backs are disabled. This means that any calls to methods in the ClientPage.ClientResponse object is ignored.

It is therefore not possible to show a modal dialog using ClientPage.ClientResponse.ShowModalDialog during load.

The following won't work:

protected override void OnLoad(EventArgs e) {

if (!Sitecore.Context.ClientPage.IsEvent) {
// won't work

A solution is to use to some JavaScript, that runs when the page has loaded, to trigger an event on the server which will show the dialog.

The FormPage control has an OnLoad property which is very useful for this scenario.

So the XML layout could look like this:

<FormPage onload="'javascript:scForm.postRequest('', '', '', 'OnShowModalDialog')">

The CodeBeside object should contain a method named OnShowModalDialog.

protected void OnShowModalDialog() {

When the page loads, the OnLoad javascript is triggered, which then sends a request to the server. The server sees this as a Sheer request and the ClientResponse object is enabled which make the ShowModalDialog work.


Post a Comment

<< Home