+ Start a Discussion
sai tarunsai tarun 

in a vf page u have 2 buttons if click button 1 then display pb1 and button1 will disable if click button2 then disply pb2 and button2 will disable

in a vf page u have 2 buttons 
   if click button 1 then display pageblock1 only,and button1 will disable
   if click button2 then disply pageblock2 only,and button2 will disable.....
Best Answer chosen by sai tarun
Mukesh_SfdcDevMukesh_SfdcDev
Hi Sai,

Please try this code

Vf Page
<apex:page controller="BtnDisableEnable" >
<apex:form >
<apex:outputPanel id="IdBtnPanel">

<apex:commandButton value="Button1" disabled="{!Btn1}" action="{!ClickBtn1}"  reRender="IdBtnPanel"/>
<apex:commandButton value="Button2" action="{!ClickBtn2}" disabled="{!Btn2}" ReRender="IdBtnPanel"/>


<apex:pageBlock id="IdPB1" rendered="{!PB1}">
    page Block 1
</apex:pageBlock>


<apex:pageBlock id="IdPB2" rendered="{!PB2}">

    Page Block 2
</apex:pageBlock>

</apex:outputPanel>
</apex:form>
</apex:page>

Controller
public class BtnDisableEnable {

Public Boolean Btn1 { get; set; }
public Boolean Btn2 { get; set; }
public Boolean PB1 { get; set; }
public Boolean PB2 { get; set; }

    public BtnDisableEnable()
    {
        Btn1 = false;
        Btn2 = false;
        
        PB1 = true;
        PB2 = true;
    }
    
    public Void ClickBtn1(){    
        Btn1 = true;
        PB2 = false;
        
        btn2 = false;
        PB1 = true;
    }
    
        public Void ClickBtn2(){    
        Btn2 = true;
        PB1 = false;
        
        Btn1 = false;
        PB2 = true;
    }
 
}

I hope this simple example will solve your problem.

Thanks 
Mukesh Kumar

All Answers

Mukesh_SfdcDevMukesh_SfdcDev
Hi Sai,

Please try this code

Vf Page
<apex:page controller="BtnDisableEnable" >
<apex:form >
<apex:outputPanel id="IdBtnPanel">

<apex:commandButton value="Button1" disabled="{!Btn1}" action="{!ClickBtn1}"  reRender="IdBtnPanel"/>
<apex:commandButton value="Button2" action="{!ClickBtn2}" disabled="{!Btn2}" ReRender="IdBtnPanel"/>


<apex:pageBlock id="IdPB1" rendered="{!PB1}">
    page Block 1
</apex:pageBlock>


<apex:pageBlock id="IdPB2" rendered="{!PB2}">

    Page Block 2
</apex:pageBlock>

</apex:outputPanel>
</apex:form>
</apex:page>

Controller
public class BtnDisableEnable {

Public Boolean Btn1 { get; set; }
public Boolean Btn2 { get; set; }
public Boolean PB1 { get; set; }
public Boolean PB2 { get; set; }

    public BtnDisableEnable()
    {
        Btn1 = false;
        Btn2 = false;
        
        PB1 = true;
        PB2 = true;
    }
    
    public Void ClickBtn1(){    
        Btn1 = true;
        PB2 = false;
        
        btn2 = false;
        PB1 = true;
    }
    
        public Void ClickBtn2(){    
        Btn2 = true;
        PB1 = false;
        
        Btn1 = false;
        PB2 = true;
    }
 
}

I hope this simple example will solve your problem.

Thanks 
Mukesh Kumar
This was selected as the best answer
sai tarunsai tarun
Hi,
Mukesh 
Thank you soo much bro........
 
Mukesh_SfdcDevMukesh_SfdcDev
Your welcome bro

Thanks
Mukesh Kumar