You can put your JAvascript on the page in a function, and then you can call it from server-side using ScriptManager.RegisterStartupScript. like this..
<script type="text/javascript" >
function RefreshAndClose() {
parent.opener.__doPostBack('btnRefresh', 'Click');
window.close();
}
</script>
// If you are using Ajax (which you are using, so u should use this one)
ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "CODE_KEY", "RefreshAndClose();", true);
// If you are not using Ajax
Page.ClientScript.RegisterStartupScript(this.GetType(), "CODE_KEY", "RefreshAndClose();", true);
--
--
Hope this helps..
--
Mark as Answer, if it answers you..
--
Marked as answer by manimike on Jul 19, 2011 12:56 PM
manimike
Member
48 Points
30 Posts
how do i get my javascript running again
Jul 19, 2011 11:13 AM|LINK
Hello,
I've read several threads on several forums, with solutions like
System.Web.UI.ScriptManager.RegisterClientScriptBlock
but I just can't get my javascript code to work, since I've been using an ajax timer on the form.
Basicly what it does is close the current form and refresh the parent form. It is executed in the save button click event. (using vs 2010)
This is the code: Can somebody please tell me what to replace this with so it will work again? Thanks a lot!
Response.Write("<SCRIPT LANGUAGE=JavaSCript>") Response.Write("parent.opener.__doPostBack('btnRefresh', 'Click');" & Chr(10)) Response.Write("window.close();") Response.Write("</SCRIPT>")hassanmehmoo...
Star
8970 Points
1590 Posts
Re: how do i get my javascript running again
Jul 19, 2011 11:41 AM|LINK
Hi,
You can put your JAvascript on the page in a function, and then you can call it from server-side using ScriptManager.RegisterStartupScript. like this..
<script type="text/javascript" > function RefreshAndClose() { parent.opener.__doPostBack('btnRefresh', 'Click'); window.close(); } </script> // If you are using Ajax (which you are using, so u should use this one) ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "CODE_KEY", "RefreshAndClose();", true); // If you are not using Ajax Page.ClientScript.RegisterStartupScript(this.GetType(), "CODE_KEY", "RefreshAndClose();", true); ----
Hope this helps..
Mark as Answer, if it answers you..
--
manimike
Member
48 Points
30 Posts
Re: how do i get my javascript running again
Jul 19, 2011 11:47 AM|LINK
Hi,
Thank you for quick response,
I have put the script on the page, between the </head> and <body> tags.
I have put the line
in the code
However nothing happens, i can see the line is processed while debugging, but the form remains open.
hassanmehmoo...
Star
8970 Points
1590 Posts
Re: how do i get my javascript running again
Jul 19, 2011 11:50 AM|LINK
Have u also inserted the JS to your form, as i mentioned?
Do u have the same name of your updatepanel as "UpdatePanel1"
--
Hope this helps..
Mark as Answer, if it answers you..
--
manimike
Member
48 Points
30 Posts
Re: how do i get my javascript running again
Jul 19, 2011 12:00 PM|LINK
Yes, i have updatepanel1 on the form, in it is a timer.
I can see the javascript in the source, in IE.
manimike
Member
48 Points
30 Posts
Re: how do i get my javascript running again
Jul 19, 2011 12:21 PM|LINK
In FF i get the following error when I press the button:
parent.opener is null
hassanmehmoo...
Star
8970 Points
1590 Posts
Re: how do i get my javascript running again
Jul 19, 2011 12:23 PM|LINK
I'd suggest to first check window.close only, and comment/ remove the line "parent.opener.__doPostBack('btnRefresh', 'Click');"
So that you should know if the JS is working or not.
Then move ahead to parent.opener operation.
--
Hope this helps..
Mark as Answer, if it answers you..
--
manimike
Member
48 Points
30 Posts
Re: how do i get my javascript running again
Jul 19, 2011 12:29 PM|LINK
Thanks for the suggestion,
'Scripts may not close windows that were not opened by script' is the error i now receive.
What thrills me it that this all worked fine before I started using the timer.
hassanmehmoo...
Star
8970 Points
1590 Posts
Re: how do i get my javascript running again
Jul 19, 2011 12:36 PM|LINK
Hmm yeah, and u'd be having this error in FF, not in IE.
For FF, there is a workaround, to tell the FF that window is actually opened by the script.
You can se the code for that here:
http://csharpdotnetfreak.blogspot.com/2008/11/javascript-windowclose-does-not-work-in.html
--
Hope this helps..
Mark as Answer, if it answers you..
--
manimike
Member
48 Points
30 Posts
Re: how do i get my javascript running again
Jul 19, 2011 12:56 PM|LINK
I can now conclude that your solution works, thank you.
However, I have two identical forms, one with and one without the ajax timer.
On the one without, the
parent.opener.__doPostBack('btnRefresh', 'Click');
works, (i can actually see the 'parent' form refreshing) and on the on with the timer it doesn't. Any idea's for another solution or a workaround?
Thanks a lot for getting the script to work!