Access to events and participants on the main page

I have an event on the main page that I want to receive on pages that use this main page, but it does not work.

In the wizard

public delegate void NotifyRequest(object sender, EventArgs e);
public class MyMaster
{
   public event NotifyRequest NewRequest;
   protected void uiBtnNewTask_Click(object sender, EventArgs e)
   { 
      if(NewRequest!= null)
         NewRequest(this, e)
   }
}

Inherited Page

MyMaster mm = new MyyMaster();
mm.NewRequest += new NotifyRequest(mm_NotifyRequest);
void mm_NotifyRequest(object sender, EventArgs e)
{
    Label1.Text = "Wow";
    this.Label1.Visible = true;
}

My problem is that the event is always zero. Any ideas?

+3
source share
1 answer

You probably need to use the following syntax to access your event on the main page

((MyMaster)Master).NewRequest += new NotifyRequest(mm_NotifyRequest);

If you want to access the elements of the main page, you need to use the Master attribute and transfer it to the main page.

Alternatively

, @MasterType, , MyMaster. , : Master.NewRequest.

+3

Source: https://habr.com/ru/post/1710006/


All Articles