Camillia
asked on
Eventhandler comes out as null
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:
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)
{...}
ASKER
i have all that code in my content page.
Master.Master.MasterTab += new MasterPageTabClickHandler( Master_Mas terTab);
*and I have:
void Master_MasterTab(object sender, RadTabStripEventArgs e)
{
string t = string.Empty;
t = "hello";
}
Master.Master.MasterTab += new MasterPageTabClickHandler(
*and I have:
void Master_MasterTab(object sender, RadTabStripEventArgs e)
{
string t = string.Empty;
t = "hello";
}
ASKER
yeah, comes out as null. I can do a check for null but wont do me anything good. I need to raise this event.
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.
ASKER
how can I hook it?? I can add the null check but i need this to be hooked...
You've already got the code for hooking the event, but this sequence appears to be happening:
You could try hooking the event in the asp tag instead of in code behind:
- Instance of AdminMaster created
- MasterTab event raised
- Exception thrown as MasterTab == null
- Hook MasterTab event, now MasterTab != null
You could try hooking the event in the asp tag instead of in code behind:
<asp:AdminMaster id="Master" runat="server" onmastertab="Master_MasterTab" />
ASKER
let me try.
ASKER
what is "onmastertab"?? I have OnTabClick event but what is onmastertab..same thing??
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_Mas terTab);
Can you tell me at what stage you are calling the line
Master.Master.MasterTab += new MasterPageTabClickHandler(
ASKER
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_Mas terTab);
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(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
let me see, hope you're right.Spent all day on this.
ASKER
YES, FINALLY, it worked. Thanks so much for your help. The entire day on this. Thanks
ie. the person person using the AdminMaster class would have to do this:
adminMaster.MasterTab += new MasterPageTabClickHandler(
and then the handler:
protected void adminMaster_MasterTab(obje
}
You should always test if the event is null when writing your own events before firing it, as it may be null.