Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
opening the new window(browser) and bringing it on the front by button click whenever i clicked it will be open in front





C#
String open = "window.open(\"AJVErrorlog.aspx?ProjectCode=" + "1200" + "&ScheduleCode=" + EncrytedString(Session["ScheduleId"] as string) + "\",'mywindow', 'height=750,width=1200, menubar=0, resizable=yes')";
       ScriptManager.RegisterStartupScript(this.ctbUpdatePanel, this.ctbUpdatePanel.GetType(), "open", open, true);
Posted
Comments
Praveen Kumar Upadhyay 22-Jul-15 8:07am    
What's wrong in your code?
Sathish km 22-Jul-15 8:14am    
when i open this window by button click, it is showing front for first time only. after i click the button it still remains opened in background.
i want to show it in front whenever i clicked button.
Praveen Kumar Upadhyay 23-Jul-15 2:42am    
It means window is already open and you are again clicking on button and want it to be active one?
Praveen Kumar Upadhyay 23-Jul-15 2:50am    
Here I am posting my answer. This can help you.
Sathish km 23-Jul-15 5:07am    
It means window is already open and you are again clicking on button and want it to be active one?


yes. it should open refreshed window

1 solution

To open a window and to be active one always, you need to set the focus to that opened window.

Below is a sample example that can help you in your scenario.

XML
<html>
<head>
<script>
var newWindow = null;

function openWindow()
{
    if(newWindow==null)
    newWindow = window.open("http://www.google.in", '_blank','height=750,width=1200, menubar=0, resizable=yes');

    newWindow.focus();
}
</script>
</head>
<body>
<input type="button" value="Click" onClick="openWindow()"/>
</body>
</html>

You need to assign the window.open() to a global variable, if you do not want to open the new window always when you click on the button. At the end just set focus to that window object.
In the above example, whenever you click on button it will bring the opened(if not open) object in front.

In your example, rather passing the complete window object set, pass only the parameters to a javascript method and open window.open there in javascript method.

May be this hint can help you.
 
Share this answer
 
Comments
Sathish km 23-Jul-15 5:03am    
Hey almost working! but the opened child window could not be refreshed
how to refresh child window while opening?
Praveen Kumar Upadhyay 23-Jul-15 5:11am    
Just add below line after newWindow.focus()

newWindow.location.reload();
Sathish km 23-Jul-15 5:03am    
thk u!
Praveen Kumar Upadhyay 23-Jul-15 9:08am    
Thank you. I am happy that I could able to help you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900