How can I call aspx content page methods from usercontrol? ASP.NET, C# -


How do I call aspx content page methods from user control?

The easiest solution is to have an interface that includes those methods that can be called user control. And then direct the interface to the control from the page, such as:

  public interface ISOMViewViewz (zero method 1); Bull Meth 2 (); } Public class MyContentPage: Page, ISomeService {Null Method 1 () {...} bool Method2 () {...} Overload Download (...) {TheUserControl.SetService (as ISomeService); }} Public class MyUserControl: UserControl {Public Zero SetService (ISomeService Service) {_service = service; } Private Zero some other method () {_service.Method1 (); }}  

To implement the interface required for another variation, user control page is required. This sets the SetService () method unnecessary: ​​

  Public class MyUserControl: UserControl {Private Zero SomeOtherMethod () {// Page should apply to ISomeService, otherwise it throws an exception (form of page In ISomeService). Method1 (); }}  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -