in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

THE Surefire Way to Open a Dialog from Codebehind on an AJAX Enabled Page

Last post 04-23-2008 11:59 AM by MarkBonafe. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 04-23-2008 11:59 AM

    THE Surefire Way to Open a Dialog from Codebehind on an AJAX Enabled Page

    OK!

    I know this has been bugging a lot of you because it's been a real hassle for me.  I am using VS 2008 C# to build my web applications.  Nearly every one of my pages has the following layout:

    <head>  ... title, styles, etc.

    <script type="text/javascript" language="javascript">

    function openDialog(dialog) { dialog.control.show(dialog); }

    function openModalDialog(dialog) { dialog.control.showModal(dialog); }

    function closeDialog(dialog) { dialog.control.Hide();  }

    </script>

    <body><form ... ><div><asp:ScriptManager ... ></asp:Scriptmanager><asp:UpdatePanel><ContentTemplate>

    ..... Page Contents .....

    </ContentTemplate></asp:UpdatePanel></div>

    .... Multiple C1WebDialogs ....

    </form></body>

    I use the C1WebDialogs to gather input from users and to display numerous messages.  Some of the messages needed to be displayed not as a result of a button push or other client-side event, but because code running on the server determined a message was required.  It could be an error message, an informational message, etc.

    I tried setting the ShowOnLoad = true, but because of AJAX, this had no affect at all - the dialog stayed hidden.

    The Answer!

    Use the ScriptManager to call the openDialog script on the form.  In your C# (or VB) code where you determine a dialog MUST be displayed, add this (where "dlgError" is the name of your dialog):

    ScriptManager.RegisterStartupScript(this, typeof(Page), "onload", "openDialog(dlgError);", true);

    You can use this method to run any valid script immediately.

    See this page for more information on the method:  ScriptManager Class - RegisterStart

     

Page 1 of 1 (1 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.