I have a master page where in I have a link button. In one of the content pages, I need to hide the linkbutton and replace with image button. The click event handler for ima
There is also the @ Master directive (MSDN Article). This method provides a way to create a strongly typed reference to the ASP.NET master page when the master page is accessed from the Master property.
The result is as stated strongly typed and there is no need to cast.
Example usage:
<%@ MasterType VirtualPath="~/masters/SourcePage.master"" %>
Using this directive actually produces the same code as @Scott's implementation but does not require you to know the type of the masterpage.
You can then start using your masterpage by lets say:
Master.Title = "My Page Title";
You will be able to invoke events from the master this way as well. Use Master.FindControl to find the master control you want.
Example of find control:
HtmlAnchor btnMyImageButton = (HtmlAnchor)Master.FindControl("btnMyImageButton");
BUT I would suggest using the OnClick property of the ImageButton and set it to a publicly accessible void/Sub on the Master page. Then simply call that void/Sub like:
Master.ImageButtonClick();