Saturday, 3 October 2015

How to access webpart method from another webpart - Kentico

Leave a Comment
This tutorial is to show how to access web part method from another webpart. This situation basically when you use repeater(webpartA) and inside repeater transformation you call another User control / webpart(webpartB). Everytime the you trigger event on the webpartB (ie: click, change value, etc), you want to refresh the webpartA value. But you cannot access the method directly.

Code Behind repeater / WebartA

Override OnInit Event
   protected override void OnInit(EventArgs e)  
   {  
   
     RequestStockHelper.Add("WebPartB", this); 
     base.OnInit(e);  
   }  



Code Behind UserControl / WebpartB

Called ReloadData() from another webpart.
   protected void LinkButton1_Click(object sender, EventArgs e)  
   {         
        
        CMSAbstractWebPart webpart = RequestStockHelper.GetItem("WebPartB") as CMSAbstractWebPart;
        if (webpart != null)
        {            
            webpart.OnContentLoaded();
        }  
}



Thats all. 


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

0 comments:

Post a Comment

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.