function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Force.platformForce.platform 

display pageBlock only after click button

Hello All,
   I have vf page, on this i have search functionality, when i enter any product name in serch box then related products display in pageBlock  in table format. but requirement, this pageBlock should dispaly only after when we click on search button, not before.
below is my code,
<apex:commandButton value="Clear Products" action="{!clear}" style="float:right;" reRender="panel"/> 
       <apex:commandButton value="Search Products" action="{!search}" style="float:right;"/>
       <apex:inputText value="{!searchstring}" label="Input" style="float:right;"/>
       
       <!-- pageBlockTable for search result-->
       <apex:outputPanel id="panel">
        <apex:pageBlock title="Search Result"> 
        <apex:pageblockTable value="{!SerchPro}" var="a"> 
        <apex:column headerValue="Product Name">
               <apex:outputLink title="View Product Detail" onclick="return openPopUp('{!a.id}') ">
               {!a.name}
               </apex:outputLink>
               </apex:column>
         <!-- <apex:column value="{!a.Quantity__c}"/>-->
        <apex:column >
        <apex:commandLink value="Add to Bucket" action="{!AddToCartButton}">
        <apex:param name="PQuantity" value="{!a.Quantity__c}"/> 
        <apex:param name="PId" value="{!a.Id}"/>
        </apex:commandLink>
        </apex:column>
        
       </apex:pageBlockTable> 
      </apex:pageBlock> 
      </apex:outputPanel> 
Suraj TripathiSuraj Tripathi
Hi Arati,

This is the Code for "Searching Products by entering Name",
It will show all products as per your requirement
When you will click on search button, then it will show all related products.

//Controller
 
public class ProductSearchAfterButtonClick {
    public string EnteredText{get;set;}
    public List<Product2> prolist{get;set;}
      
    public PageReference SearchResult()
    {
		prolist= [SELECT Name, ProductCode, Family, Description FROM Product2 
					WHERE Name Like :'%'+EnteredText+'%' ];	
		return null;      
    }
}

//VF Page
<apex:page controller="ProductSearchAfterButtonClick">
	<apex:form >
		<apex:outputLabel style="font-weight:bold;" value="Enter Name to Search: " >
        </apex:outputLabel>
        <apex:inputText value="{!EnteredText}"/>
       	<apex:commandButton value="Search" action="{!SearchResult}"/>
        <apex:pageBlock >
        	  <apex:pageBlockTable value="{!prolist}" var="pro">
                    <apex:column >
                        <apex:facet name="header">Name</apex:facet>{!pro.Name}
                    </apex:column>
                  	<apex:column >
                        <apex:facet name="header">ProductCode</apex:facet>{!pro.ProductCode}
                  	</apex:column>
                  	<apex:column >
                        <apex:facet name="header">Family</apex:facet>{!pro.Family}
                  	</apex:column>
                    <apex:column >
                        <apex:facet name="header">Description</apex:facet>{!pro.Description}
                    </apex:column>
              </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>    
</apex:page>

You Can Make Changes as per your requirement in this code ​

Hope this will meet your requirement
If this helps you, Please Mark this answer as Best Answer

Regards
Suraj
Force.platformForce.platform
Hi Suraj
       My requirement is, i want to show pageBlock only when i enter any product name in searchbox and click on serach button. before searching there should nothing display pageBlock on page
Suraj TripathiSuraj Tripathi
Hi Arati,

Sorry for the late reply,

Please Try this Code, Maybe now it will solve your problem


//Controller
 
public class ProductSearchAfterButtonClick {
    public string EnteredText{get;set;}
    public List<Product2> prolist{get;set;}
    public Boolean showSection1{get;set;}
    
    public PageReference SearchResult()
    {
        prolist= [SELECT Name, ProductCode, Family, Description FROM Product2 WHERE Name Like :'%'+EnteredText+'%' ];
        showSection1= true;
        return null;        
    }
}



//VF Page
 
<apex:page controller="ProductSearchAfterButtonClick">
	<apex:form >
		<apex:outputLabel style="font-weight:bold;" value="Enter Name to Search: " >
        </apex:outputLabel>
        <apex:inputText value="{!EnteredText}"/>
       	<apex:commandButton value="Search" action="{!SearchResult}" reRender="block"/>
        <apex:pageBlock id="block">
        	  <apex:pageBlockTable value="{!acclist}" var="acc" rendered="{!showSection1}">
                    <apex:column >
                        <apex:facet name="header">Name</apex:facet>{!pro.Name}
                    </apex:column>
                  	<apex:column >
                        <apex:facet name="header">ProductCode</apex:facet>{!pro.ProductCode}
                  	</apex:column>
                  	<apex:column >
                        <apex:facet name="header">Family</apex:facet>{!pro.Family}
                  	</apex:column>
                    <apex:column >
                        <apex:facet name="header">Description</apex:facet>{!pro.Description}
                    </apex:column>
              </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>    
</apex:page>


If this code helps you to render your pageblock only after click of search button, then please don't forget to mark this answer best
so this question will removed from unsolved threads


Regards
Suraj