views:

735

answers:

2

I'm showing a modal dialog via "window.showModalDialog(..." which happens in a vbscript function (the page shown is aspx). I'd like to do some resizing of the window based on the number of rows in a datatable that's coming back. So naturally I go to register a startup script that resizes the window based on the number of rows. Well, that didn't work, so I tried to register a script that just showed a msgbox.

The code looks like (in the OnLoad event handler):

 if (!this.ClientScript.IsStartupScriptRegistered(typeof(MyPageClassName), "hello"))
        {
            this.ClientScript.RegisterStartupScript(typeof(MyPageClassName), "hello",
                    @"<script language=vbscript>
                        sub fnWindowOnLoad()
                         MsgBox ""hello""
                        end sub
                        <script>", false);
        }
        if (!this.ClientScript.IsStartupScriptRegistered(typeof(MyPageClassName), "hello"))
        {
            throw new Exception("Failed to load script");
        }

To me it looks like this should work and show a message box that says "hello" when the page loads (I've got the window's onload event set to fnWindowOnLoad). But what happens is nothing, no exception, no alert. I've tried every Type I could think of in the typeof call. Nothing seems to work. The only thing I can think of is that since the dialog is a modal ClientScript.RegisterStartupScript won't run properly. But that doesn't make any sense to me.

I put the MsgBox "hello" call into my script block directly and the alert showed, so it's possible. But I need to modify some arguments in the code behind so I have to use RegisterStartupScript as far as I can tell.

A: 

Have you tried opening your window via window.open() rather than window.showModalDialog()? I've seen some postings on the web about incompatibilities between showModalDialog() and RegisterStartupScript.

showModalDialog() is an IE only method, so it's not recommended anyway. I know it's convenient because it returns a value, but there are various ways to simulate this functionality.

Edit: The other problem with showModalDialog() is that IE often caches the results. This means that if one time you calling the dialog, you do not resize it, then another time you do, then 2nd time might get your the first cached dialog. A way to get around this is to add a unique querystring at the end. Like MyDialog.aspx?q=320934 (randomly generated or generated based on server tics).

Keltex
my boss isn't gonna be happy if I get rid of the showModalDialog; plus it involves a lot of other changes; I really need the value that comes back; we're an IE only company and will remain so for years i suspect
jcollum
@jcollum See my edit above. That's the other problem I've seen.
Keltex
sigh, you're right. but if I start fixing things the right way around here I'll have to start from scratch and I don't have mgmt buy-in on that
jcollum
A: 

The solution for this was to have a script that read a value out of a hidden field and then resized the dialog. The value was set on the Page_Load. Using RegisterStartupScript never seemed to work, neither did RegisterClientScript, so I'm pretty sure modal dialog and RegisterXxx don't get along. Need to use window.dialogHeight & window.dialogWidth in the vbscript.

jcollum