21

I'd like to use a modalpopupextender in my asp.net page to show a sub form. But it only has to show on specific conditions. Those conditions are determined in a piece of javascript code.

So, most importantly, the modal popup doesn't have to show on a button click. However, if I leave the property TargetControlID empty I get the following exception:

The TargetControlID of 'ModalPopupExtender1' is not valid. The value cannot be null or empty. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The TargetControlID of 'ModalPopupExtender1' is not valid. The value cannot be null or empty.

Do I just have the TargetControlID to an hidden button or is there aslo a more decent option?

MPelletier
  • 16,256
  • 15
  • 86
  • 137
Herman Cordes
  • 4,628
  • 9
  • 51
  • 87
  • You used the HiddenField or the Button control as the target control Id. Did you face any difficulties having hiddenfield as targetcontrolId because i am now – Deeptechtons May 04 '11 at 09:37
  • 1
    @Deeptechtons, don't use a HiddenField. Use a Button control, but hide it with css (style="display: none;") as Mike mentioned in his answer. – Herman Cordes May 04 '11 at 14:25
  • you are perfectly right. The button solved my problem wonder what's wrong in using hidden fields – Deeptechtons May 05 '11 at 06:09

3 Answers3

24

Setting the TargetControlID to a hidden button(display:none;) is the best way as far as I know.

Mike
  • 5,437
  • 7
  • 45
  • 62
13

The TargetControlID could also be set to a HiddenField type. That way you don't even need a button

lovingit
  • 131
  • 1
  • 2
0

Crete a button and set it as your TargetControlId and give style = "display:none"

<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="Panel1" TargetControlID="btnPopup" 
        CancelControlID="btnClose" BackgroundCssClass="modalBackground" OkControlID="btnClose"></asp:ModalPopupExtender>

<asp:Button ID="btnPopup" runat="server" Text="PopUp" style = "display:none" />
Tunaki
  • 132,869
  • 46
  • 340
  • 423
fahim
  • 1