execute 'window.open' client script function in server side code

I am using button control(web control) on my page (ReportControl.aspx).

On button_click I want to open another page ReportViewer.aspx (in new browser) but before that I should able to collect control values of ReportControl.aspx and pass to that new page. So that i will use them on page_load of that new page(ReportViewer.aspx).

Please reply urgent.

1
Bhushan
7/2/2008 9:21:08 AM
asp.net.client-side 24353 articles. 1 followers. Follow

20 Replies
981 Views

Similar Articles

[PageSpeed] 43

Use this:

ScriptManager.RegisterStartupScript(this, typeof(string), "OpenWindowScript", "window.open('ReportViewer.aspx');", true);

1
kipo
7/2/2008 9:29:50 AM

Thanks kipo for your reply.

How i pass parameter to this page (i collect parameter values in for loop on server side).

1
Bhushan
7/2/2008 9:46:47 AM

You can pass them if you put them in QueryString:

ScriptManager.RegisterStartupScript(this, typeof(string), "OpenWindowScript", "window.open('ReportViewer.aspx?param1=" + param1 + "&param2=" + param2 + "');", true);
and you will collect them in second page like this:
string param1 = Request.QueryString["param1"];

-1
kipo
7/2/2008 9:52:37 AM

Can I use session variales to pass values as parameter. Whether it will work for opening same multiple times with different parameter on button_click.

1
Bhushan
7/2/2008 9:57:29 AM

Yes, you can use Sessions too.

-1
kipo
7/2/2008 10:00:28 AM

 var cust=$("hidCustomerId").value;
        var custname=$("hdCustomer").value;
       
            window.open('AddressLookUp.aspx?AddressType='+ addressType +'&cust='+ cust+'&custname='+custname,null,'width=600,height=300,toolbar=no,scrollbars=yes,resizable=no,dependent=yes');
       

Here i am opening a page which is sending the customerId and address type in the query string which the child can access in its load event. 

Don't be puzzled with those "$"  signs. It is used coz i used prototypejs framework. You can simply replace those with document.getElementById() method


If this post was useful to you, please mark it as answer. Thank you!
aspxdev.blogspot.com
-1
aalokitoaami
7/2/2008 10:07:51 AM

Thanks kipo. It's working well.

But how do i set focus to that new window and show it on the top of other window(parent window).

1
Bhushan
7/2/2008 10:15:41 AM

Hi........

from your post i got that u have to do some operation on your button click and then you need to post your values to another page..if i am wrong then correct me....

this can be achieved like this.....

private void button1_Click(object sender,eventargs e)

{
    //get the operation done on the button click.....
    //say you want to navigate to webform1.aspx with id

Response.Write("<script>window.open('Webform1.aspx?id=1','_parent',replace=true);</script>");

}

if any problems then ask.....first of all clear my doubt that i have understood what u are trying to achieve......

bye.... 


Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial
to other community members reading the thread.
1
gopsy_25
7/2/2008 10:24:55 AM

Thanks for reply.

You are correct. I got the solution.

Here is my code

page.clientScript.RegisterStartupScript(GetType(String),"OpenWindow","window.open('RptPreview.aspx');",True)

 This will open that page in new browser. Now i just want to set that browser window on top of other window(Parent window).

Pls reply urgent.

-1
Bhushan
7/2/2008 10:40:44 AM

Hi kipop.

please reply urgent.

1
Bhushan
7/2/2008 10:41:58 AM

so just change one thing. instead window.open('RptPreview.aspx'); use this line.....

window.open('RptPreview.aspx','_parent',replace=true);

this will work for you......

bye............... 


Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial
to other community members reading the thread.
1
gopsy_25
7/2/2008 10:52:51 AM

Please quit with the urgent stuff. That is not going to get results faster and it is a little irritating since most people have other jobs also. Try this

ScriptManager.RegisterStartupScript(this, typeof(string), "OpenWindowScript", "winRef = window.open('ReportViewer.aspx?param1=" + param1 + "&param2=" + param2 + "'); winRef.focus();", true);

NC...

-1
NC01
7/2/2008 11:07:25 AM

Hi, gopsy.

I want to open New page in new browser not in same browser.

New page with new browser should display on top of other windows(Parent browser window).

Please reply urgent.

1
Bhushan
7/2/2008 11:12:33 AM

Hi, NC01

it's working.

Actually after postback focus was on my parent window control.

1
Bhushan
7/2/2008 11:23:33 AM

Try this, and this time post what happens, not just "it's not working"

string javaScript = string.Format(
 "winRef = window.open('ReportViewer.aspx?param1={0}&param2={1}'); winRef.focus();",
 param1, param2)

ScriptManager.RegisterStartupScript(this, typeof(string), "OpenWindowScript", javaScript, true);

NC...

-1
NC01
7/2/2008 11:38:31 AM

Hi.

It's working thanks.

1
Bhushan
7/2/2008 11:46:49 AM

 hi....

just use the following changes..............

window.open('Default.aspx','_blank',replace=false);

for further doubt please give some example so we can understand what do u want......

bye...... 


Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial
to other community members reading the thread.
1
gopsy_25
7/3/2008 7:08:51 AM

Hi gopsy 25, it's working . Now I want to set new browser size to 'maximum' (exact to size of screen).

Pls reply urgent.

-1
Bhushan
7/3/2008 7:17:13 AM

 window.open('default.aspx','_blank','top=200,left=50,width=640,height=430,scrollbars=yes,toolbars=yes,status=yes',replace=false);


Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial
to other community members reading the thread.
1
gopsy_25
7/3/2008 7:59:41 AM

Thanks alot.

Can you please tell me solution to my another question:

I am using master page and content page functionality in asp.net 2.0

I have menu control on master page.

But MenuItemclick event on master page does not  fire for second time(It fires on one menu click but after that not on other menu click). It loads same page again. I have not set NavigateUrl property of menuitems.

Please reply urgent.

 

1
Bhushan
7/3/2008 9:53:38 AM
Reply:

Web resources about - execute 'window.open' client script function in server side code - asp.net.client-side

Resources last updated: 1/15/2016 5:41:04 AM