Solved

Eventhandler comes out as null

Posted on 2009-03-30
13
552 Views
Last Modified: 2012-05-06
Not sure what I'm doing wrong here.
I have a Telerik RadStrip control in my AdminMaster page. I added OnTabClick to the RadStrip. I added a Delegate and an eventHandler but not sure why the eventhandler comes out as null:


1. <telerik:RadTabStrip ID="MainMenu" runat="server" AutoPostBack="true" OnTabClick="Tab_Click"   Skin="Outlook">
                    <Tabs>
                          ...
 
2. Outside the AdminMaster class
public delegate void MasterPageTabClickHandler(object sender, RadTabStripEventArgs e);
 
3. Inside AdminMaster class:
public event MasterPageTabClickHandler MasterTab; //*** MasterTab comes out as null
 
4. protected void Tab_Click(object sender, RadTabStripEventArgs e)
    {...}

Open in new window

0
Comment
Question by:Camillia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
13 Comments
 
LVL 15

Expert Comment

by:oobayly
ID: 24021480
The event has to be hooked for it to be usable:
ie. the person person using the AdminMaster class would have to do this:
adminMaster.MasterTab += new MasterPageTabClickHandler(adminMaster_MasterTab);

and then the handler:
protected void adminMaster_MasterTab(object sender, RadTabStripEventArgs e){
}

You should always test if the event is null when writing your own events before firing it, as it may be null.

0
 
LVL 7

Author Comment

by:Camillia
ID: 24021558
i have all that code in my content page.

Master.Master.MasterTab += new MasterPageTabClickHandler(Master_MasterTab);

*and I have:

 void Master_MasterTab(object sender, RadTabStripEventArgs e)
   {
    string t = string.Empty;
        t = "hello";
    }
0
 
LVL 7

Author Comment

by:Camillia
ID: 24021601
yeah, comes out as null. I can do a check for null but wont do me anything good. I need to raise this event.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 15

Expert Comment

by:oobayly
ID: 24021620
It then sounds like your trying to fire the event before it's been hooked. It's a bad idea to assume that the event is always hooked, hence checking if it's null.
0
 
LVL 7

Author Comment

by:Camillia
ID: 24021657

 how can I hook it?? I can add the null check but i need this to be hooked...
0
 
LVL 15

Expert Comment

by:oobayly
ID: 24022026
You've already got the code for hooking the event, but this sequence appears to be happening:
  1. Instance of AdminMaster created
  2. MasterTab event raised
  3. Exception thrown as MasterTab == null
  4. Hook MasterTab event, now MasterTab != null
You obviously never get to step 4.

You could try hooking the event in the asp tag instead of in code behind:

<asp:AdminMaster id="Master" runat="server" onmastertab="Master_MasterTab" />

Open in new window

0
 
LVL 7

Author Comment

by:Camillia
ID: 24022082
let me try.
0
 
LVL 7

Author Comment

by:Camillia
ID: 24022112
what is "onmastertab"?? I have OnTabClick event but what is onmastertab..same thing??
0
 
LVL 15

Expert Comment

by:oobayly
ID: 24022248
Sorry, my bad, we're talking about a masterpage, not a webcontrol aren't we.

Can you tell me at what stage you are calling the line
Master.Master.MasterTab += new MasterPageTabClickHandler(Master_MasterTab);
0
 
LVL 7

Author Comment

by:Camillia
ID: 24022297
that's in my content page.

 void Master_MasterTab(object sender, RadTabStripEventArgs e)
    {
        string t = string.Empty;
        t = "hello";
    }
    protected void Page_Load(object sender, EventArgs e)
    {



       Master.Master.MasterTab += new MasterPageTabClickHandler(Master_MasterTab);
0
 
LVL 15

Accepted Solution

by:
oobayly earned 500 total points
ID: 24022352
Aha, in page load. Try hooking the event in Page_Init, this is fired before Page_Load, so you may have more luck.
More information about when ASP.Net page event are fired ASP.Net Page Life Cycle


  protected void Page_Init(object sender, EventArgs e) {
     Master.Master.MasterTab += new MasterPageTabClickHandler(Master_MasterTab);
  }

Open in new window

0
 
LVL 7

Author Comment

by:Camillia
ID: 24022383
let me see, hope you're right.Spent all day on this.
0
 
LVL 7

Author Comment

by:Camillia
ID: 24022512
YES, FINALLY, it worked. Thanks so much for your help. The entire day on this. Thanks
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question