0 down vote favorite
I've been working on an asp.net website, where i need to open a browser window from c# code behind. I created the following JS on aspx page.
JS:
function openPopUp() { window.open("About.aspx?something=happening", "WindowPopup", "width=700px, height=500px, resizable"); }
and this C# code
C#:
protected void Button1_Click(object sender, EventArgs e) { string script = "Sys.Application.add_load(openPopUp);"; ClientScript.RegisterStartupScript(this.GetType(), "openPopUp", script); }
The above code works fine, and shows the About.aspx page as a new browser window. But, the problem is whenever the parent page does a postback(e.g. whenever i try to sort the radgrid on parent page), it opens the browser window again.
I've googled it, but didn't found helpful workaround to this problem, maybe i would need to unregister the client script which is being registered on Button1_Click, if so then lemme know how can i detach or unregister the script once the browser window is closed so that the same browser window doesn't shows again and again on each postback.
any help would be highly appreciated!
Loading
Iftikar HussainPosted Jun 30, 2013, 10:24 AM
Please tell your condition. I beleive you can do it in client side only. Provide me the details
Regards,
Iftikar
suleman altafPosted Jun 30, 2013, 8:27 AM
But, i've a scenario where i've an asp.net button, on its onClick i need to execute some c# script, and once certain condition is met- i need to show the popup.
I can show the popup from code behind by registering startup script, but the problem is whenever the parent page postbacks it re-registers the script again- which again show the popup.
Can you help me how can i remove the startup script from aspx page after i close the browser window by closing it.
Iftikar HussainPosted Jun 30, 2013, 1:40 AM
Don't open a new window from code behind. You can do it directly from client side only as shown below
Iftikar