MyWebPage page = Page as MyWebPage; if (page != null) page.UpdateText("New Text");
Dim page As MyWebPage If Page <> Nothing Then page.UpdateText("New Text"); End IfThat works OK but it limits the control to only working on that specific page. One way around that is to create an interface for the page which requires a page to implement an "UpdateText" method, ex:
public interface IMyWebPage { void UpdateText(string newText); } public partial class MyWebPage : System.Web.UI.Page, IMyWebPage { protected void Page_Load(object sender, EventArgs e) { } public void UpdateText(string newText) { // Code specific to this page does something with the newText passed in. } }
Public Interface IMyWebPage Sub UpdateText(ByVal newText As String) End Interface Public Partial Class MyWebPage Inherits System.Web.UI.Page Implements IMyWebPage Public Sub UpdateText(ByVal newText As String) '' code spec. End SubWe'd then change the code in the ASCX file to:
IMyWebPage page = Page as IMyWebPage; if (page != null) page.UpdateText("New Text");
Dim page As IMyWebPage If Page <> Nothing Then page.UpdateText("New Text"); End IfYet another way would be to create an event on the user control which fires, then bind to it from the ASPX page. If you need an example for that, let me know.