You need to sign in to do that
Don't have an account?
Problem in executing java script method and controller method simultaneously in a single event.
Hi
can anyone tell me how a java script method and controller method executed at same button click...?
<apex:commandButton value="Turn Quote Into Order" action="{!forOrder}" style="float:left" rerender="Outputpanelid" oncomplete="window.top.close()"/>
controller method is forOrder
public PageReference forOrder() {
Id Id = ApexPages.currentPage().getParameters().get('Id');
quoteId = ApexPages.currentPage().getParameters().get('quoteId');
PageReference newpage = new PageReference('/apex/pcontactdetail?Id='+Id+'"eId='+quoteId);
newpage.setRedirect(true);
return Page.newpage;
}
when I execute this code window is not be closed but anather page is opened.that means may be java script method is not executed.
If any one have suggestion help me with example......
Hi,
Try the below code sample
function refreshandclose()
{
window.setTimeout('window.top.close();', 10);
window.top.parent.location = '/apex/searchcontact'; //Here you have to give the page name of the page present in the parent window
}
</script>
</head>
<apex:commandButton value="Turn Quote Into Order" action="{!forOrder}" style="float:left" rerender="Outputpanelid" onclick="window.top.close();" />
public pagereference forOrder()
{
Id Id = ApexPages.currentPage().getParameters().get('Id');
quoteId = ApexPages.currentPage().getParameters().get('quoteId');
PageReference newpage = new PageReference('/apex/pcontactdetail);
system.debug('@@@@@@@@@@@@@@@'+id + quoteId);
if(Id != null && quoteId != null)
newpage = new PageReference('/apex/pcontactdetail?Id='+Id+'"eId='+quoteId);
try
{
newpage.setredirect(true);
}
catch(Exception ex)
{
ApexPages.addMessages(ex);
}
return newpage;
}
All Answers
Looking at your controller method, you are redirecting to the new page that means on click of button,you will navigate to another page, and as soon as you got on new page, the oncomplete has no means, because just before completing you will be on new page.
Hi,
You can try below sample code:
<apex:commandButton action="{!forOrder}" value="Turn Quote Into Order" onclick="window.top.close()" style="float:left" rerender="Outputpanelid" />
I think onclick function executes before the action. Can you make sure ?
Hi hemantgarg
I tried by writing on click instead of on complete .But by this window is simply closed .I think apex method may not be executed. Actually my requirement is popup window should be closed at the same time parent window is refreshed and populate a QuoteId which I am trying to send to parent window from popup window.These two page have same controller .I have also tried by writting window.opener.closepopup();.Still its not working please help me.some times a new page is opened in the popup window without being closed ......please help me
Hi,
Try the below code
<apex:commandButton value="Turn Quote Into Order" action="{!forOrder}" style="float:left" rerender="Outputpanelid" oncomplete="refreshandclose();" />
<head>
<script language='javascripts'>
function refreshandclose()
{
window.setTimeout('window.top.close();', 1000);
}
</script>
</head>
<apex:commandButton value="Turn Quote Into Order" action="{!forOrder}" style="float:left" rerender="Outputpanelid" oncomplete="window.top.close();" />
public pagereference forOrder()
{
Id Id = ApexPages.currentPage().getParameters().get('Id');
quoteId = ApexPages.currentPage().getParameters().get('quoteId');
PageReference newpage = new PageReference('/apex/pcontactdetail);
system.debug('@@@@@@@@@@@@@@@'+id + quoteId);
if(Id != null && quoteId != null)
newpage = new PageReference('/apex/pcontactdetail?Id='+Id+'"eId='+quoteId);
try
{
newpage.setredirect(true);
}
catch(Exception ex)
{
ApexPages.addMessages(ex);
}
return newpage;
}
Hi Navatar
Thanks for replying .I did what you suggested.But popup window is not being closed rather a new page is opened in this popupwinow.But I want popup window should be closed. parent window will be upadated with quoteId.
please help me
Hi,
Try the below code sample
function refreshandclose()
{
window.setTimeout('window.top.close();', 10);
window.top.parent.location = '/apex/searchcontact'; //Here you have to give the page name of the page present in the parent window
}
</script>
</head>
<apex:commandButton value="Turn Quote Into Order" action="{!forOrder}" style="float:left" rerender="Outputpanelid" onclick="window.top.close();" />
public pagereference forOrder()
{
Id Id = ApexPages.currentPage().getParameters().get('Id');
quoteId = ApexPages.currentPage().getParameters().get('quoteId');
PageReference newpage = new PageReference('/apex/pcontactdetail);
system.debug('@@@@@@@@@@@@@@@'+id + quoteId);
if(Id != null && quoteId != null)
newpage = new PageReference('/apex/pcontactdetail?Id='+Id+'"eId='+quoteId);
try
{
newpage.setredirect(true);
}
catch(Exception ex)
{
ApexPages.addMessages(ex);
}
return newpage;
}
Hi
I treid but Still I am facing same problem.
Any other suggession.