ModalPopupExtender without TargetControlID

You need to specify Control ID (clicking on this control trigger to open modal popup) to TargetControlID property of ModalPopupExtender control and TargetControlID is required property.  If you don’t set value to TargetControlID property or you set empty value, you would get error “The TargetControlID of ‘ModalPopupExtender1’ is not valid. The value cannot be null or empty.”.

ASP.NET generates JavaScript for us that makes control(control specified in PopupControlID) visible to true.   The logic to open popup is done through JavaScript and because of that Page_Load event won’t fired.  You may be in a situation that you need to leave that property empty for example you need to open the modal popup from code behind or you need to set TargetControlID property dynamically or you need to execute some code on server side before modal popup opens.

Here is the work around (way to make compiler fool :))

  • Have hidden button control and set its control id to TargetControlID property
  • Create another button control and OnClick event of this control
    protected void Button1_Click(object sender, EventArgs e)
    {
         //Execute some code
         mpe.Show();
    }
    

Hope this helps.
Happy Programming!!!!
Posted in Microsoft Technology Tagged with:
2 comments on “ModalPopupExtender without TargetControlID
  1. fitocuba says:

    Great!its helpful.Thank you :)

  2. shafeeq says:

    When i hidden my button my Model div is highlighted on page while loading itself

Ads