473,480 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Pop Up Window from .cs file

SJ
Is it possible to pop-up a window from the code-behind
aspx.cs file on an OnClick event?
If so, how?
I've tried something like the following, but it doesnt seem to work.

private void MyButton_Click(object sender, System.Web.UI.ImageClickEventArgs
e)
{
Response.Write("<script>window.open('mypopUp_dialo g.aspx');<script>");
}

I don't want to use in-line javascript code or use a <script> tag within my
aspx file
itself.
Nov 19 '05 #1
5 7093
it would work if your turned off you browsers popup blocking. to not be
blocked, the win.open() must be from a browser client onclick event, not a
postback.

-- bruce (sqlwork.com)

"SJ" <my******@sbcglobal.net> wrote in message
news:YV***************@newssvr13.news.prodigy.com. ..
Is it possible to pop-up a window from the code-behind
aspx.cs file on an OnClick event?
If so, how?
I've tried something like the following, but it doesnt seem to work.

private void MyButton_Click(object sender,
System.Web.UI.ImageClickEventArgs
e)
{
Response.Write("<script>window.open('mypopUp_dialo g.aspx');<script>");
}

I don't want to use in-line javascript code or use a <script> tag within
my
aspx file
itself.

Nov 19 '05 #2
insert this to your code:

string popupScript =
"<script language='javascript'>" +
"window.open('PopupPage.aspx','Popup', 'width=700, height=600, menubar=no, resizable=no')" +
"</script>";

Page.RegisterStartupScript("PopupScript", popupScript);
Nov 19 '05 #3
SJ
Doesnt work. :(
Thanks though.

-SJ
<ma**********@gmailSSSPPPAAMMM.com> wrote in message
news:dg**********@sunce.iskon.hr...
insert this to your code:

string popupScript =
"<script language='javascript'>" +
"window.open('PopupPage.aspx','Popup', 'width=700, height=600, menubar=no, resizable=no')" + "</script>";

Page.RegisterStartupScript("PopupScript", popupScript);

Nov 19 '05 #4
The problem is that you forgot the forward slash in the close script tag.
That causes the code to throw an error and not execute. You need to make
the last tag </script>.

"SJ" <my******@sbcglobal.net> wrote in message
news:YV***************@newssvr13.news.prodigy.com. ..
Is it possible to pop-up a window from the code-behind
aspx.cs file on an OnClick event?
If so, how?
I've tried something like the following, but it doesnt seem to work.

private void MyButton_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Response.Write("<script>window.open('mypopUp_dialo g.aspx');<script>");
}

I don't want to use in-line javascript code or use a <script> tag within my aspx file
itself.

Nov 19 '05 #5
Joe
//add this class and then you can call MessageBox.Show("string");
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;

namespace InnisMaggioreGroup
{
/// <summary>
/// Summary description for MessageBox.
/// </summary>
public class MessageBox
{
private static Hashtable m_executingPages = new Hashtable();

private MessageBox(){}

public static void Show( string sMessage )
{
// If this is the first time a page has called this method then
if( !m_executingPages.Contains( HttpContext.Current.Handler ) )
{
// Attempt to cast HttpHandler as a Page.
Page executingPage = HttpContext.Current.Handler as Page;

if( executingPage != null )
{
// Create a Queue to hold one or more messages.
Queue messageQueue = new Queue();

// Add our message to the Queue
messageQueue.Enqueue( sMessage );

// Add our message queue to the hash table. Use our page
reference
// (IHttpHandler) as the key.
m_executingPages.Add( HttpContext.Current.Handler,
messageQueue );

// Wire up Unload event so that we can inject
// some <B style="COLOR: black; BACKGROUND-COLOR:
#99ff99">JavaScript</B> for the alerts.
executingPage.Unload += new EventHandler(
ExecutingPage_Unload );
}
}
else
{
// If were here then the method has allready been
// called from the executing Page.
// We have allready created a message queue and stored a
// reference to it in our hastable.
Queue queue = (Queue) m_executingPages[
HttpContext.Current.Handler ];

// Add our message to the Queue
queue.Enqueue( sMessage );
}
}
// Our page has finished rendering so lets output the
// <B style="COLOR: black; BACKGROUND-COLOR: #99ff99">JavaScript</B>
to produce the <B style="COLOR: black; BACKGROUND-COLOR: #ff9999">alert's</B>
private static void ExecutingPage_Unload(object sender, EventArgs e)
{
// Get our message queue from the hashtable
Queue queue = (Queue) m_executingPages[
HttpContext.Current.Handler ];

if( queue != null )
{
StringBuilder sb = new StringBuilder();

// How many messages have been registered?
int iMsgCount = queue.Count;

// Use StringBuilder to build up our client slide <B
style="COLOR: black; BACKGROUND-COLOR: #99ff99">JavaScript</B>.
sb.Append( "<script language='javascript'>" );

// Loop round registered messages
string sMsg;
while( iMsgCount-- > 0 )
{
sMsg = (string) queue.Dequeue();
sMsg = sMsg.Replace( "\n", "\\n" );
sMsg = sMsg.Replace( "\"", "'" );
sb.Append( @"alert( """ + sMsg + @""" );" );
}

// Close our JS
sb.Append( @"</script>" );

// Were done, so remove our page reference from the hashtable
m_executingPages.Remove( HttpContext.Current.Handler );

// Write the <B style="COLOR: black; BACKGROUND-COLOR:
#99ff99">JavaScript</B> to the end of the response stream.
HttpContext.Current.Response.Write( sb.ToString() );
}
}
}
}

"Dave Hagerich" wrote:
The problem is that you forgot the forward slash in the close script tag.
That causes the code to throw an error and not execute. You need to make
the last tag </script>.

"SJ" <my******@sbcglobal.net> wrote in message
news:YV***************@newssvr13.news.prodigy.com. ..
Is it possible to pop-up a window from the code-behind
aspx.cs file on an OnClick event?
If so, how?
I've tried something like the following, but it doesnt seem to work.

private void MyButton_Click(object sender,

System.Web.UI.ImageClickEventArgs
e)
{
Response.Write("<script>window.open('mypopUp_dialo g.aspx');<script>");
}

I don't want to use in-line javascript code or use a <script> tag within

my
aspx file
itself.


Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

29
4954
by: wayne | last post by:
Hey there... I'm having some problems passing url parameters with an open.window command. I'm not terribly familiar with java script but here is the code below. When executed it opens the...
4
47413
by: Bill | last post by:
I need help closing a CMD window when it is executed from Access. 1) The batch file is called from Access. 2) Access closes, 3) the batch runs a copy of the access database (creating a backup)...
4
5507
by: Bill | last post by:
I need help closing a CMD window when it is executed from Access. 1) The batch file is called from Access. 2) Access closes, 3) the batch runs a copy of the access database (creating a backup)...
1
11527
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
1
3580
by: soms2m | last post by:
HELLO ALL, I want to fill the parent window height with respect to the sub window height which is loading using ajax (mootools). For example if the parent window height is normal and the loading...
0
7037
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7034
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7076
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6732
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4472
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2990
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
174
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.