I have an asp.net "search" screen which displays the results in a new browser window ewhen the user presses the submit button.
My problem is as follows:
- User searches for "smith", presses submit, gets a new results window with "smith" results in.
- User searches for "brown", presses submit, and the previous results window is reused.
Here's the code I call OnS开发者_C百科ubmit:
string strScript = "window.open('searchresults.aspx', 'Key', 'height=500,width=800,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,titlebar=yes');";
ScriptManager.RegisterStartupScript(this, typeof(string), uniqueKey, strScript, true);
How can I get a new window each time?
Thanks in advance,
Jim
First, you don't need to use JS to submit to a new window. You can just use
<form target="_blank"> ... </form>
Using this the form will always be submitted to a new window.
If you must use the script you have, just remove the second parameter to open()
(make it null). That second parameter is a name for the window you create. So you when you call it again, it'll reuse the window with the same name.
Try specifying '_blank' for the name of the window instead of 'Key'
Pass in the Key as a query string and pass null to the second parameter to window.open.
Ex:
string strScript = "window.open('searchresults.aspx?key=smith', null, 'height=500,width=800,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,titlebar=yes');";
ScriptManager.RegisterStartupScript(this, typeof(string), uniqueKey, strScript, true);
精彩评论