Popup Window generated from Server Side

  • Thread starter Thread starter HarveyB
  • Start date Start date
H

HarveyB

I would like to generate non-modal popup windows from
ASP.Net code-behind. I have tried using Client Side
scripting like "function Test(){
window.open('test.htm',_blank,
'height=200,width=400,status=no,toolbar=no,
menubar=no,location=no resizable=no
scrollable=no');
but I can't seem to invoke the client side script from
within a Server Side Form. I know I can use the context
with to Response.redirect or Server.transfer to return a
different page, but can't figure how generate a pop-up
window for an 'About' page or a "Contacts" page.
 
HarveyB said:
I would like to generate non-modal popup windows from
ASP.Net code-behind.

How about using Response.Write in your server side code:

Response.Write("<script language='javascript'>window.open(....)</script>");
 
-----Original Message-----



How about using Response.Write in your server side code:

Response.Write("<script language='javascript'>window.open
I don't think that solves the problem. It will place a
script on the returned page, but how is the script invoked
from the Server Side. The issue here is to open a pop-up
window from the server side. 'Window' is a client-side
object.

Harvey Bernstein
 
Hi HarveyB,

I do not believe that there is a method to open a client window without
using the client script.
For security concern, it is non-security to open a window from server-side.
Did I answer your question?

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
 
You cannot invoke windows from the server without using some form of
remoting listener loaded at the client. HTTP is get/response protocol and
doesn't work like that.

The best you can do is pass out the information to invoke the window client
side with client side script, either from a buttonclick/hyperlink or via a
script event such as onload for body. There is some code for one of these
below.
--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
----------------------------------------------

<html>
<head>
<script language="VB" runat="server">

Sub Page_Load( sender as Object,e as EventArgs)

'Form the script that is to be registered at client side.
Dim scriptString as String = "<script language=JavaScript> function
DoClick() {"
ScriptString +=
"window.open('http://www.mvps.org','MyWindow','width=500,height=500');}<"
scriptString += "/"
scriptString += "script>"

If(Not IsClientScriptBlockRegistered("clientScript"))
RegisterClientScriptBlock("clientScript", scriptString)
End If
End Sub
</script>
</head>
<body topmargin="20" leftmargin="10">
<form id="myForm" runat="server">

<INPUT id="launchButton" onclick="DoClick();" type="button"
value="Submit" name="myButton" runat="server">


</form>
</body>
</html>
 
The sample worked, but unfortunately I think I will need
to re-architect to do what I want. I have 3 problems.

1. The buttons are implemented inside an ASP:Datalist Cntl.
2. The plan was to encapsulate my menus in a user cntl
(ascx).
3. I am using code-behind.

Should I just go back to the drawing board. Each of the
conditions above seems to make implementing the sample
extremely difficult, if not impossible.

That is somewhat of a disappointment give that all 3 are
touted as advantages of ASP.NET.
 
Ok, then is there a way to pass a message (of some type)
to the client side so that a client side javascript can be
fired to open the window.

I mean 'message' in the most generic meaning of the term.
I just want some way to detect the button click inside the
Datalist, handle the event on the server-side and then
hand it off to the client side. The reason for this is so
that the menu inside the datalist control can be dynamic
and based on either an XML file or a SQL Query.

It seems that this should be easy, but I have tried quite
a few ideas without success.
 
Hi Harveyb,

Since the Browser/Server modal is based on request. That is to say, the
server will response to client browser with the html code at last when the
client make a request.
The server can not actively generate the html file (i.e. javascript )
without the browser request.
Have you check the suggestion of Steven, it is one method to invoke the
javascript in code behind?
Have you also check my last post that can handle the click event in the
datalist in my last post?

Did I answer your question?
If you have any related question,please feel free to let me know.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
Content-Class: urn:content-classes:message
From: "Harveyb" <[email protected]>
Sender: "Harveyb" <[email protected]>
References: <[email protected]>
<[email protected]>
 
The replies by both you and Steven are good as far as they
go. They explain that it is possible on the server side
to create and then register a client script.

That means that a user could click a button that would
postback a request for information. If you wish to return
the info in a pop-up, non-modal window, you could generate
a script to initiate the popup.

Of course you are still left with the problem of how that
script gets invoked. Having the user press ANOTHER button
is clearly not acceptable. Using an event such
as 'onload' is only useful if there is some way for the
script to determine what/when it is to take action.
The 'onload' event would fire everytime the page was
invoked, but the window.open would be discretionary.
There needs to be some mechanism to pass a message between
server and client in order for the script to know what to
do.

The obvious possibility would be in a hidden input
control. But the client side script seems to have trouble
reading the hidden control, especially if the control is
encapsulated in a User Control. It seems the User Control
compile process pre-pends the id of the User Control to
the control id, but the script can't use that name. So
there doesn't seem to be any way for the script to read
the value of the hidden control.

This make the proposed solution either extremely difficult
or perhaps impossible. Perhaps the correct approach is to
write a Server Control. That seems like an unnecessarily
complex approach, but may be the correct way to approach
this. Perhaps User Controls are best thought of as Server-
side includes.

HarveyB
 
Hi Harveyb,

For the design of Browser/Server modal, I think you may use a javascript
function to restrieve the message from server repeatedly.
e.g.
You have two pages.
page1: the main page you show the datalist to the client.
page2: the page used to response the message to client just as you "push"
the message to the client.
a javascript function run repeatedly to retrieve the data from page2.
function querystatus()
{
GetXMLHTTP();//a customer function to retrieve the msg the server want
to response to the client.
setTimeout(querystatus,300);
}

For detailed information, please refer to the link below.
http://groups.google.com/groups?q="lewis+wang"+activeXobject&hl=zh-CN&lr
=&ie=UTF-8&oe=UTF-8&selm=%249sGgp0YDHA.2172%40cpmsftngxa06.phx.gbl&rnum=1

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
Content-Class: urn:content-classes:message
From: "HarveyB" <[email protected]>
Sender: "HarveyB" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
 
I have developed a popup control to accomplish what you want. It will
open a child window and responds to postback events. It can be placed
on an ASP.NET page like this:

<PowerUI:Popup id="pPopup" runat="Server" PopupWidth="300px"
PopupHeight="300px" OnPopupPostBack="pPopup_PostBack"
UrlToPop="UserEdit.aspx">Edit</PowerUI:Popup>

Clicking on "Edit" will open the the page UserEdit.aspx in a window.
The child window can also be opened by issuing:

pPopup.PopupWindow();

in the code-behind....

Notice that you can subscribe a method to the event "OnPopupPostBack".
This is fired from executing the static method on the child window
code-behind like this:

Popup.CloseWindow(Page,true,"PostBack Message",true);

The parameters are as follows:
1. Current "Page" object
2. Fire postback event on Parent Page
3. Optional argument in case you want to pass something back to the
parent page
4. Close the child window after postback.


This can be used in a data list or datagrid for popping up edit/detail
windows. To use the Popup control in a datagrid might look like this:

<asp:DataGrid id="dgGrid" runat="server">
<columns>
<asp:TemplateColumn>
<ItemTemplate>
<PowerUI:Popup id="pEdit" runat="server"
OnPopupPostBack="pEdit_PostBack" UrlToPop='<%# "UserEdit.aspx?UserID="
+ ((User)Container.DataItem).UserID %>'>Edit</PowerUI:Popup>
</ItemTemplate>
</asp:TemplateColumn>
</columns>
</asp:DataGrid>


If your interested in the control I can email to you as an Alpha
version. I will be selling the control soon so I will not be
providing source code...
 
I will examine your sample code as to it appicability to
communicating between Server and Client.

As to the original topic, we were on the right track. It
only required a slight twist. If one creates and
registers JavaScript code on the Server Side, but does NOT
wrap it in a function, the registered code will execute as
inline script after Page_Load. This does allow a popup
window to be invoked from the Server-Side. I have tested
this in IE and Netscape.

Thx, I consider the original issue closed. I may wish to
pursue the issue of messaging between server & client in a
new thread.

Harvey
 
Back
Top