You need to sign in to do that
Don't have an account?
Shephali Swarnkar
how to open a pageblock on button click
Hi All,
Below is my code.Here i want to show the record on button click.but its not working.
<!--VF Code-->
<apex:page controller="Contacts">
<apex:form >
<apex:commandButton action="{!processSelected}" value="Process Selected" reRender="pageBlock, pageBlockProcessed" status="AjaxStatus">
</apex:commandButton>
<apex:outputPanel id="thePanel">
<apex:pageBlock title="Selected Records" id="pageBlockProcessed">
<apex:pageBlockTable value="{!selectedContacts}" var="l">
<apex:column value="{!l.Name}"></apex:column>
<apex:column value="{!l.Email}"></apex:column>
<apex:column value="{!l.Phone}"></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>
</apex:page>
//Controller code
public class Contacts
{
public list<contact> selectedContacts{set;get;}
public void processSelected()
{
selectedContacts=[select Name, Email, Phone from contact];
}
}
Below is my code.Here i want to show the record on button click.but its not working.
<!--VF Code-->
<apex:page controller="Contacts">
<apex:form >
<apex:commandButton action="{!processSelected}" value="Process Selected" reRender="pageBlock, pageBlockProcessed" status="AjaxStatus">
</apex:commandButton>
<apex:outputPanel id="thePanel">
<apex:pageBlock title="Selected Records" id="pageBlockProcessed">
<apex:pageBlockTable value="{!selectedContacts}" var="l">
<apex:column value="{!l.Name}"></apex:column>
<apex:column value="{!l.Email}"></apex:column>
<apex:column value="{!l.Phone}"></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>
</apex:page>
//Controller code
public class Contacts
{
public list<contact> selectedContacts{set;get;}
public void processSelected()
{
selectedContacts=[select Name, Email, Phone from contact];
}
}
As i check your code, your code was fine and it was working but in the reRender Part of the command button there is no need to reRender pageblock because for reRender you have to mention the id but you was mention the pageblock name and the another thing is that there was no need of output panel in your page.
<apex:page controller="ContactsController">
<apex:form >
<apex:commandButton action="{!processSelected}" value="Process Selected" reRender="pageBlockProcessed" status="AjaxStatus"/>
<apex:pageBlock title="Selected Records" id="pageBlockProcessed">
<apex:pageBlockTable value="{!selectedContacts}" var="l">
<apex:column value="{!l.Name}"></apex:column>
<apex:column value="{!l.Email}"></apex:column>
<apex:column value="{!l.Phone}"></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
public class ContactsController {
public list<contact> selectedContacts{set;get;}
public void processSelected()
{
selectedContacts=[select Name, Email, Phone from contact];
}
}
Thanks for your reply.its working now. As Gyanendra metioned and karan you too corrected that code is fine the problem was with reRender part only.
Thanks to both of you again.