ASP.NET How to change Page controls via custom UserControl? -


i have on page label control , custom usercontrol. want that, when appears in usercontrol, shoud change e.g label's text property (as mentioned, label doesn't belong usercontrol). how ?

your best bet use sort of event notify containing page usercontrol updated.

public class mycontrol : usercontrol {     public event eventhandler somethinghappened;      private void somefunc() {         if(x == y) {             //....              if(somethinghappened != null)                 somethinghappened(this, eventargs.empty);         }     } }  public class mypage : page {      protected void page_init(object sender, eventargs e) {         myusercontrol.somethinghappened += myusercontrol_somethinghappened;     }      private void myusercontrol_somethinghappened(object sender, eventargs e) {         // it's business time     } } 

this basic example, recommend using designer interface specify user control's event handler assignment gets handled in designer code-behind, rather 1 you're working in.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -