Popup Browser window

  • Thread starter Thread starter A.M
  • Start date Start date
A

A.M

Hi,

I require to have a button on the weinforms pages such that upon user click
on the button, the event handler pops up another browser window to another
url and current browser screen remains unchanged.
How can i do that?

Thanks,
Ali
 
Thanks for reply,
The problem is I have to write something into the database and then pop that
window.
Can I send some special HTTP header code to responce object so it just pop
another window in client side and don't change the current window content?

Thanks again,
Ali
 
In addition to what Curt_C said you could also do the following

Inside the postback event handler(in your case a submit button???), after your db updates add (in C#

Page.RegisterStartupScriptBlock("", "<script language=\"Javascript\">window.open(yoururl and other window properties)</script>")

This will be rendered on the HTML page after postback and Javascript(when it's executed on rendering) will open the new window

Suresh

----- A.M wrote: ----

Thanks for reply
The problem is I have to write something into the database and then pop tha
window
Can I send some special HTTP header code to responce object so it just po
another window in client side and don't change the current window content

Thanks again
Al




Curt_C said:
you'll have to use clientside code with a window.open(
Curt Christianso
Owner/Lead Developer, DF-Softwar
www.Darkfalz.co
 
special note: that most popup blockers will prevent this method from
working. also so should winxp sp2 (which has a popup blocker) when its
released.


-- bruce (sqlwork.com)



Suresh said:
In addition to what Curt_C said you could also do the following.

Inside the postback event handler(in your case a submit button???), after your db updates add (in C#)

Page.RegisterStartupScriptBlock("", "<script
language=\"Javascript\">window.open(yoururl and other window
properties) said:
This will be rendered on the HTML page after postback and Javascript(when
it's executed on rendering) will open the new window.
 
So what would be the best method haveing a new browser window contains the
some information ?
 
Thanks Steven for reply,

I saw the aspx file and i like the idea of having <a> tag and trigger it
using OpenWindow(url) when we want to popup the browser window.

I think you missed the file OpenWindow.aspx.cs. could you send it as well ?

Thanks again,
Ali
 
Hi Ali,

Thanks for your response. Well I'll paste the page's source here:

---------------------------aspx----------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>OpenWindow</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
function openwindow(url)
{
lnkNewWindow.href = url;
lnkNewWindow.click();
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td>
<asp:Label id="lblMessage" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Button id="btnPostBack" runat="server"
Text="PostBack"></asp:Button></td>
</tr>
<tr>
<td>
<a id="lnkNewWindow" href="http://www.asp.net" target="_blank"
style="DISPLAY:none"></a>
</td>
</tr>
</table>
</form>
</body>
</HTML>

-----------------------------------aspx.cs page
class----------------------------------------
public class OpenWindow : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnPostBack;
protected System.Web.UI.WebControls.Label lblMessage;

private void Page_Load(object sender, System.EventArgs e)
{

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{

InitializeComponent();
base.OnInit(e);
}


private void InitializeComponent()
{
this.btnPostBack.Click += new
System.EventHandler(this.btnPostBack_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnPostBack_Click(object sender, System.EventArgs e)
{
lblMessage.Text = "Button is clicked at: " +
DateTime.Now.ToLongTimeString();
string sb = "<script language='javascript'>openwindow('{0}');</script>";
sb = string.Format(sb,"http://www.microsoft.com");
Page.RegisterStartupScript("startscript",sb);
}
}

-------------------------------------------------------------------

If you have any further questions or anything unclear, please feel free to
post here.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
Back
Top