javascript window.open via button click event in code behind

Hello!

I'm trying to open a new window on a click event.

If I use the attributes.add in the Page_Load, then pop-up window gets hit before an update occurs...hence, the pop-up window is just a little too early.

I'm trying this in my button click event, but it's not bringing up the new window:

Response.Write("")

Thanks!

0
Bubberz
4/1/2008 5:27:19 PM
📁 asp.net.client-side
📃 24353 articles.
⭐ 1 followers.

💬 17 Replies
👁️‍🗨️ 1636 Views

You wanna use Page.ClientScript.RegisterStartupScript.  This is the solution. 

0
scott976
4/1/2008 5:37:55 PM

Add a StartupScript something like this: 

protected void Button1_Click(object sender, EventArgs e)
{
	this.ClientScript.RegisterStartupScript(
		this.GetType(),
		"Window",
		"window.open('../../../Default.aspx','','width=500,height=320,left=200,top=200');",
		true);
}

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
4/1/2008 5:40:28 PM

Hello!

Thanks for the replay, I'm using VB, but this is not liking the Page.ClientScript part...saying 'Client Script' is not a member of 'system.UI.web.page':

Page.ClientScript.RegisterStartupScript(Me.GetType(), "Window", "window.open('UpdateBudgetConfirm.aspx?UBID=" + strSAID + "','','width=500,height=320,left=200,top=200');", True)

0
Bubberz
4/1/2008 5:52:46 PM

I got this to compile correctly, but it's not firing:


  Page.RegisterStartupScript("Window", "window.open('UpdateBudgetConfirm.aspx?UBID=" + strSAID + "','','width=500,height=320,left=200,top=200');")

 

0
Bubberz
4/1/2008 6:02:16 PM

Are you using at least the 2.0 Framework?


Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
4/1/2008 6:03:58 PM

Bubberz:

Page.RegisterStartupScript("Window", "window.open('UpdateBudgetConfirm.aspx?UBID=" + strSAID + "','','width=500,height=320,left=200,top=200');")

Looks like you're not using 2.0. Add the script tags into your window.open call.


Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
4/1/2008 6:07:22 PM

Hi...sorry...v1.1

0
Bubberz
4/1/2008 6:13:53 PM

For future reference, please note that you are using 1.1 in any further posts. This will help your answerer greatly.


Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
4/1/2008 6:17:19 PM

Still no luck:

Page.RegisterStartupScript("Window", "")

0
Bubberz
4/1/2008 6:23:55 PM

Sorry, but I don't event have a 1.1 environment that I can test this in anymore. Can anyone else test this?


Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
4/1/2008 6:40:25 PM

I've tried the following in Page_Load, but I get a syntax error:

Page.RegisterStartupScript("Window", "")

btnYes.Attributes("onclick") = "AlertUpdate()"

 

0
Bubberz
4/1/2008 7:26:24 PM

Hi,

There€™s a gramma issue in your code. It should be:

Page.RegisterStartupScript("jwb", " ");

In your code:
Page.RegisterStartupScript("Window", "")

There€™s an unnecessary parenthesis.

Thanks.


Michael Jin.
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Nai
4/7/2008 6:49:23 AM

Thank you for this post. but I tried it with Ajax enabled website but it is not working. is this code working with ajax sites or not if not can you please help me and post a code do the same thing working with Ajax websites.

 Best regards,
Sms

0
webhay
4/8/2008 3:50:22 PM

That will not work with AJAX, since the code requires a full page load/re-load to fire.

NC...

 

0
NC01
4/8/2008 4:34:09 PM

Thanks for the reply but do you have any idea how can I solve this problem.

Regars,

Sms

 

0
webhay
4/8/2008 4:58:58 PM

The only thing that I can suggest is to move to 2.0 since it has functionality built in for handling that situation.

ScriptManager:
http://www.asp.net/ajax/documentation/live/overview/ScriptManagerOverview.aspx
ScriptManager.RegisterStartupScript:
http://www.asp.net/ajax/documentation/live/mref/M_System_Web_UI_ScriptManager_RegisterStartupScript_5_0feb167c.aspx

NC...

0
NC01
4/8/2008 5:07:40 PM

Thank you so much...

sms

0
webhay
4/8/2008 10:52:42 PM