This is a migrated thread and some comments may be shown as answers.

Null Reference Exception when post back occurs

1 Answer 84 Views
ToolTip
This is a migrated thread and some comments may be shown as answers.
Joshua Horton
Top achievements
Rank 1
Joshua Horton asked on 04 Mar 2009, 01:59 PM
I have a page that has a RadComboBox and a RadGrid that displays plans and is grouped by the plan type. Specs call for the user to be able to filter which type and only that type to see. I am using the RadComboBox to be able to select which type to filter by, which post back and updates the grid accordingly. I am also using a RadAjaxManagerProxy to do the updating with the ComboBox and Grid in the settings.

The issue is that I am using a RadTooltipManager to tooltipifiy the details in the Grid Rows and works perfectly on the initial render. But when I select a new item from the ComboBox and the Grid begins to update there is a Null Reference exception being thrown because it says it can not find the control with the id that is being added to the RadTooltipManager's TargetControl collection.

I have commented out the two lines where the add to the TargetControl collection takes place and everything works fine.  And the reason why I'm needing to add to the TargetControl collection is because there are some buttons that do not need to be tooltipified.  One question I'm wondering about is do I need to update the TooltipManager when a postback occurs? I'll attach a code segment below that will show how I have the TargetControl.Add().

Thank you for any advice on this matter.

protected void gridAllPlans_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem) 
            { 
                var targetPlanYearName = e.Item.FindControl("planYearName"); 
                var targetPlanName = e.Item.FindControl("planName"); 
                if (!Equals(targetPlanYearName, null)) 
                { 
                    if (!Equals(this.radToolTipManager, null)) 
                    { 
                        var year = (PlanPlanYearInfo)e.Item.DataItem; 
                         
                        if (year.PlanPlanYear != null
                            ((WebControl)targetPlanYearName).Attributes["OnMouseOver"] = String.Format("DisplayPlanYearName('{0}', '{1}');", targetPlanYearName.ClientID, year.PlanPlanYear.PlanYearId); 
 
                        ((WebControl)targetPlanName).Attributes["OnMouseOver"] = String.Format("DisplayPlanName('{0}', '{1}');", targetPlanName.ClientID, year.Plan.Id); 
                         
                        radToolTipManager.TargetControls.Add(targetPlanName.ID); 
                        radToolTipManager.TargetControls.Add(targetPlanYearName.ID); 
                    } 
                } 
            } 
        } 

1 Answer, 1 is accepted

Sort by
0
Svetlina Anati
Telerik team
answered on 06 Mar 2009, 03:20 PM
Hello Joshua,

I suggest to try adding the ClientID to the TargetControls colection and also provide true boolean argument for the isClientID property in the same method. As to your question, when you update the target controls you should update the RadToolTipManager also because it needs to update the values for targets. You can fins a demo about updating targets below:

http://demos.telerik.com/aspnet-ajax-beta/tooltip/examples/targetcontrolsandajax/defaultcs.aspx


Regards,
Svetlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
ToolTip
Asked by
Joshua Horton
Top achievements
Rank 1
Answers by
Svetlina Anati
Telerik team
Share this question
or