Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing Event Handlers from Two Different Master Pages
    text
    copied!<p>I have a ASP.NET content page where the master page is set dynamically. Both master pages contain a print button and an associated event handler for the click event of the button. Unfortunately I receive a run-time error when I attempt to dynamically access the event from the master page that was not initially assigned.</p> <p>Below are code snippets:</p> <pre><code> &lt;%@ Page Language="VB" MasterPageFile="~/Evaluators/masEvaluators.master" AutoEventWireup="false" CodeFile="EDF_Instructions.aspx.vb" Inherits="Evaluators_EDF_Instructions" Title="EDF - Instructions" %&gt; Page_Load(): Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim strPageTitle As String = "Evaluator Data Form - Instructions" If Page.MasterPageFile.Contains("masEvaluators.master") Then Dim mp As Evaluators_masEvaluators = CType(Me.Master, Evaluators_masEvaluators) AddHandler mp.SaveEDF, AddressOf imgbtnPrint_Click ElseIf Page.MasterPageFile.Contains("masStaff.master") Then Dim mp As Evaluators_masEvaluators = CType(Me.Master, Evaluators_masEvaluators) CType(Page.Master.FindControl("imgbtnPrint"), ImageButton).Visible = True AddHandler mp.SaveEDF, AddressOf imgbtnPrint_Click End If </code></pre> <p>which produces the following error when I load the page and reference the "masStaff.master" master page:</p> <p><code>System.InvalidCastException: Unable to cast object of type 'ASP.staff_masstaff_master' to type 'Evaluators_masEvaluators'. at Evaluators_EDF_Instructions.Page_Load....</code></p> <p>I can solve the problem by adding a print button to the content page, but that defeats the purpose of using a master page. </p> <p>Is there a solution to this problem? I have spent many hours researching this issue on the web, but have not found a solution as of yet.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload