Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

new window

Status
Not open for further replies.

HrvojeVd

Programmer
Jun 22, 2008
36
HR
I'm using javascript to open a new window, but as a result I get refreshed main page.
How to prevent that?
 
what javascript are you using? window.open?

you need to set a return variable so rather than

Code:
window.open('http...')

you should set

Code:
var x = window.open('http...')
 
I'm using this code:

string script = "window.open('news.aspx')";
if (!ClientScript.IsClientScriptBlockRegistered("NewWindow"))
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "NewWindow", script, true);
}
 
Change it to:

Code:
string script = "var x = window.open('news.aspx')"; 
if (!ClientScript.IsClientScriptBlockRegistered("NewWindow"))
{ 
     ClientScript.RegisterClientScriptBlock(this.GetType(), "NewWindow", script, true);
}
 
Where is that code being called from? If it is from any asp.net button type, the page will refresh because of a post back. Also, you are mixing asp.net server side code inside of your javascript:

ClientScript.RegisterClientScriptBlock AND
ClientScript.IsClientScriptBlockRegistered - is server side code, not javascript code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top