Solved

Eventhandler comes out as null

Posted on 2009-03-30
13
547 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What .NET URL re-routing tool did I use? 2 56
SQL Login 17 50
System.Speech 2 27
Problem!!! 8 33
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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