You need to sign in to do that
Don't have an account?
yogesh_patil
how to avoid a visualforce page from getting refreshed after calling apex method on button click?
this is my visualforce code...
Actually i want to show the loading image button on click of upload attachment button
On click of select Attachment the apex method is being called which makes the page to rfresh...
i want to avoid the page refresh...
and rerender cannot be used on <apex:inputfile>
////////visualforce code /////////
<apex:page standardController="Account" extensions="extendAccountforstandardController">
<apex:form id="frm">
<apex:pageBlock >
<apex:pageblockSection >
<apex:inputFile value="{!objAttachment.body}" fileName="{!objAttachment.name}"/>
</apex:pageblockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Select Attachment" action="{!selectAttachment}" rerender="none" />
</apex:pageBlockButtons>
</apex:pageBlock>
<apex:actionRegion >
<apex:pageBlock id="pgBlkId" >
<apex:pageBlockSection >
<apex:inputField value="{!objAccount.parentid}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:outputpanel id="image">
<apex:commandButton action="{!attachRecord}" value=" upload attachment" reRender="image" status="actStatusId" />
</apex:outputpanel>
<apex:actionStatus id="actStatusId" >
<apex:facet name="start" >
<img src="/img/loading.gif" />
</apex:facet>
</apex:actionStatus>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:actionRegion>
</apex:form>
</apex:page>
///// Apex Code
public class extendAccountforstandardController {
public PageReference attachRecord() {
System.debug('@@objAccount.id'+objAccount.id);
System.debug('@@objAccount.parentId'+objAccount.parentId);
objAttachment.parentId=objAccount.parentId;
objAttachment.body=bodyAttachment;
objAttachment.name=nameAttachment;
if(objAccount.parentid!=null){
insert objAttachment;
}
return null;
}
public blob bodyAttachment;
public string nameAttachment;
public Account objAccount { get; set; }
public Attachment objAttachment {get; set;}
public extendAccountforstandardController(ApexPages.StandardController controller) {
objAccount =new Account();
objAttachment=new Attachment();
}
public void selectAttachment(){
bodyAttachment=objAttachment.body;
nameAttachment=objAttachment.name;
System.debug(''+'@@nameAttachment'+nameAttachment);
}
}
Actually i want to show the loading image button on click of upload attachment button
On click of select Attachment the apex method is being called which makes the page to rfresh...
i want to avoid the page refresh...
and rerender cannot be used on <apex:inputfile>
////////visualforce code /////////
<apex:page standardController="Account" extensions="extendAccountforstandardController">
<apex:form id="frm">
<apex:pageBlock >
<apex:pageblockSection >
<apex:inputFile value="{!objAttachment.body}" fileName="{!objAttachment.name}"/>
</apex:pageblockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Select Attachment" action="{!selectAttachment}" rerender="none" />
</apex:pageBlockButtons>
</apex:pageBlock>
<apex:actionRegion >
<apex:pageBlock id="pgBlkId" >
<apex:pageBlockSection >
<apex:inputField value="{!objAccount.parentid}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:outputpanel id="image">
<apex:commandButton action="{!attachRecord}" value=" upload attachment" reRender="image" status="actStatusId" />
</apex:outputpanel>
<apex:actionStatus id="actStatusId" >
<apex:facet name="start" >
<img src="/img/loading.gif" />
</apex:facet>
</apex:actionStatus>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:actionRegion>
</apex:form>
</apex:page>
///// Apex Code
public class extendAccountforstandardController {
public PageReference attachRecord() {
System.debug('@@objAccount.id'+objAccount.id);
System.debug('@@objAccount.parentId'+objAccount.parentId);
objAttachment.parentId=objAccount.parentId;
objAttachment.body=bodyAttachment;
objAttachment.name=nameAttachment;
if(objAccount.parentid!=null){
insert objAttachment;
}
return null;
}
public blob bodyAttachment;
public string nameAttachment;
public Account objAccount { get; set; }
public Attachment objAttachment {get; set;}
public extendAccountforstandardController(ApexPages.StandardController controller) {
objAccount =new Account();
objAttachment=new Attachment();
}
public void selectAttachment(){
bodyAttachment=objAttachment.body;
nameAttachment=objAttachment.name;
System.debug(''+'@@nameAttachment'+nameAttachment);
}
}
Since you have used <form> tag so your page is posting back. You can use onclick="return false;" to avoid form POST.
Thanks
Ajay Rawat
<apex:commandButton value="Select Attachment" action="{!selectAttachment}" rerender="none" onclick="return false;"/>
rerender option doesnot work here..
please come acroos with different options..
<apex:commandButton value="Select Attachment" action="{!selectAttachment}" rerender="none" oncomplete="return false;"/>