0

I have a radio list in my master page and they fire an event when I select one of them.

Now this event isn't not controlled by my master page instead it is controlled by my content page. My question is, is it possible to pass int/Strings from the master page method to content page method somehow.

P.S i want to pass the int i to content page method in this case

This is how i tide them up.

Master page Code to handle event

public event EventHandler Master_Save;
  ...
public void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
    int i=RadioButtonList1.SelectedIndex;        
    if(Master_Save!=null)
    { Master_Save(this, EventArgs.Empty); }
}

and my content page code to handle the event

protected override void OnPreInit(EventArgs e)
{
    base.OnPreInit(e);
    (this.Page.Master as Pages_MasterPage).Master_Save += new EventHandler(ContentPage_Save);
}

 private void ContentPage_Save(object sender, EventArgs e)
{
    //Code that changes a query   

 }

1 Answers1

0

Sure you can, just define a custom event args class and parametrize your event with it:

public class MasterSaveEventArgs : EventArgs
{
    public int Index { get; private set; }
    public MasterSaveEventArgs(int index)
    {
        this.Index = index;
    }
}

And then just use it:

public event EventHandler<MasterSaveEventArgs> Master_Save;
...
{ Master_Save(this, new MasterSaveEventArgs(i)); }
...
(this.Page.Master as Pages_MasterPage).Master_Save += ContentPage_Save;
// notice the shortened syntax here
...
private void ContentPage_Save(object sender, MasterSaveEventArgs e)
Andrei
  • 55,890
  • 9
  • 87
  • 108
  • Thank you for your response. However there is an error on my PreInt method to be exact on my EventHandler line. Can you help me figure that – user3070259 Dec 24 '14 at 12:23
  • @user3070259, edit the answer. for future cases, it is always useful to specify *what error* you are experiencing, otherwise you are leaving others to guess – Andrei Dec 24 '14 at 12:27