views:

79

answers:

1

I am building a modal box as a custom server control and I want to have a property on the modal box TargetControlID that specifies the element that will show the modal when clicked. I've set the property up in the modal box and in the code behind I use the following code block (which I've tried in several different places

    If (_targetControlId <> "") Then
        Dim targetControl As WebControl = Me.Page.FindControl(_targetControlId)
        targetControl.Attributes.Add("onclick", "test1();")
        targetControl.Attributes.Add("onclick", "test2();")
    End If

What happens is that targetControl always winds up to be NULL, and causes the page to crash when I tried to add attributes to it. I've double checked the spelling of the targetControlId and I am specifying a control that is runat="server". What is the proper way for a server control to access other controls on its containing page?

Thanks,

Mike

A: 

First of all, I should point out that the behavior you're looking for already exists in the ModalPopupExtender that comes with the free, open-source AjaxControlToolkit. I'd recommend you just use that. If you're still sure you want to write your own, then I'd recommend at least taking a look at their code to see how they go about it. ExtenderControlBase.FindControlHelper is a good place to start.

StriplingWarrior
You're right, I should just go with the extender. I just finished creating my own CollapsiblePanel because the CollapsiblePanelExtender didn't quite suit my needs, however the modal extender should fit my requirements perfectly. Thanks.
Mike C