Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > HTML > HTML Code Clinic
|
HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the HTML Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 22nd, 2003, 07:24 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default Displaying modal dialog from server code

I need to display a modal dialog box in response to a server event. However, when I do this the parent form temporarilly clears itself until the dialog box is closed. I am left with a modal dialog box with a blank form underneath. When this is done using client code the parent form does not clear. Does anyone know what I am doing wrong. I am using the following code (.NET):-

Response.Write("<script>window.showModalDialog('fr mSubject.aspx', null,'dialogHeight:350px;dialogWidth:700px;center: yes;help:no;scroll:no;status:no');</script>");

Cheers,
Gary

 
Old December 22nd, 2003, 08:29 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hmmm, first of all I wouldn't use Response.Write. Instead, write the contents to a Literal control that you place somewhere on the page.

A better approach is to use RegisterStartUpScript. That will write a block of (JavaScript) code to the end of the page, so it will fire when the parent page has loaded (almost) completely.

A third, and maybe even better approach, is to write a JavaScript function to open the new window to a Literal control. Then, add code to the onload event of the <body> tag to call the function defined in the JavaScript block.

Does this make sense?

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 22nd, 2003, 10:34 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your reply.

The example I gave was actually a simplified version of what I need to do. I need to perform some server processing in response to the event BEFORE calling the script. The script that I output is actually dependent on this server processing, e.g. The form that pops up and it's parameters can vary. I'm not sure I can achieve this using RegisterStartUpScript or RegisterClientScriptBlock. Any ideas?

Using Response.Write seemed to be the simplest way of achieving the above - if only it didn't cause the parent page to clear. Unfortunately I'm not familiar with Literal controls having come from a Windows programming background straight to ASP.NET

Many thanks,
Gary


 
Old December 22nd, 2003, 10:50 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Well, see for yourself if it is any good:

http://msdn.microsoft.com/library/de...criptTopic.asp

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 22nd, 2003, 01:38 PM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Unfortunately, I don't think that's going to enable me to do the server processing I need.

If I register a client script block, doesn't that mean that I can only respond to the event with client-side code? The majority of my event handling needs to be on the server - with the dialog pop-up being the only client code. If I register a client-side event handler I don't think I can also have a server-side event handler. Am I correct?

Does anyone know the answer to my original question? Can this be done with Response.Write without the parent form clearing?

Thanks for your help,
Gary

 
Old December 22nd, 2003, 02:33 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Did you actually *read* the page I referred you to??

Quote:
quote:Remarks
Similar to the RegisterClientScriptBlock method, this method emits the script just before the closing tag of the Page object's <form runat= server> element. The script block is emitted as the object that renders the page is defined, so you must include both tags of the <script> element.

By identifying the script with the key, multiple server control instances can request the script block without it being emitted to the output stream twice.

Any script blocks with the same key parameter values are considered duplicates.

Note Remember to include HTML comment tags around your script so that it will not be rendered if a requesting browser does not support scripts.
All this method does is send JavaScript to the browser and places it at a predefined location in the page.
What "server side processing" do you need?

I also think that my other solutions (use the onload of the <body> tag) would work. I think the page turns blank because you're opening a modal dialog while still downloading the parent page. If you wait until the parent page has finished loading, then use onload to open the modal dialog, I think the page won't go blank anymore.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 23rd, 2003, 05:10 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Of course I read the page you referred me to.

Like I said in my last message, I need to do a large amount of server-side processing in response to an event. It doesn't matter what "server side processing" I need, it HAS to be done! Please explain to me how I can then use RegisterClientScriptBlock to output a modal dialog box once this has been done.

I'm definitely not "still downloading the parent page" when I'm opening the modal dialog. As a test I moved the Response.Write statement to the end of Page_Load() and I still get the same problem.

Cheers,
Gary

 
Old December 23rd, 2003, 05:43 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It could be me, but I think the example is on the page I linked to. Here's a short version of the code example:
Code:
<html>
  <head>
    <script language="C#" runat="server">
    public void Page_Load(Object sender, EventArgs e)
    {
        string scriptString = "<script language=JavaScript> alert('Hello');";
        scriptString += "</";
        scriptString += "script>";
        this.RegisterStartupScript("Startup", scriptString);
    }
     </script>
  </head>
  <body topmargin="20" leftmargin="10" onload="Page_Load()">
     <form id="myForm" runat="server">

     </form>
  </body>
</html>
When you run this page, it will inject the JavaScript for the alert box right before the closing </form> tag. This will cause the alert box to pop up when almost the entire page has loaded. You can still do extensive server side processing (never said you couldn't, I was just trying to figure out your requirements) before the alert will fire.

If this is not what you're after, I am lost in figuring out your requirements.....


Imar



---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 23rd, 2003, 06:37 AM
Authorized User
 
Join Date: Nov 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Imar - I just needed to know that I could do the server processing as well.

However, it still ldoes not fix my problem. I am still finding that the parent form clears whilst the dialog box is displayed. Any ideas?


Many thanks,
Gary

 
Old December 23rd, 2003, 06:42 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

If you look at the HTML source of the page in the browser, where is the code for the new window / dialog located?


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to return value from modal dialog ajaypsingh Javascript 2 May 16th, 2006 05:14 AM
Scrolling modal dialog to top gp_mk HTML Code Clinic 3 September 15th, 2004 07:04 AM
server control event in modal dialog diyagp General .NET 0 August 26th, 2004 02:57 AM
Modal dialog window eldanh ASP.NET 1.0 and 1.1 Basics 0 August 10th, 2004 02:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.