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

OutbackDirect.co.uk is a trading site of World of Power.co.uk Limited. Outback Direct is the official Outback Consumer Warranty, Parts and Accessory Partners for the UK. We currently hold in stock 1000’s of parts and accessories for current and older Outback barbecues. We endeavour to ensure rapid and secure product delivery the length and breadth of mainland United Kingdom, this factor coupled with our excellent customer service has led to the market position we currently enjoy.
outback barbecue
omega 300 gas barbecue
Omega 250 Gas Hooded BBQ
Blog
Blog
------------------------------------------------------------ Silver Sky Imports is a unique online marketplace that offers unique handicrafts from Tibet and Nepal. Launched in 2003, Silver Sky Imports is currently the largest supplier of handmade items from the Himalayas. We specialize in the largest variety of Tibetan Singing Bowls and Crystal Singing Bowls online and include individual sound samples, pictures and descriptions for each bowl. Some of our other products include Tibetan Prayer Flags, Tingshas, Bell and Dorje, Incense, Felted Wool Handbags, Wood Masks, Prayer Wheels, Gongs, Bronze Statues, and Tibetan Meditation Rugs. monks
Blog
------------------------------------------------------------ Airpush, a mobile ad network that is only two years old, has quickly grown to one with over 5,000 advertisers. One thing they've heard from that sea of advertisers over the past 12 months, and especially over the past six, is that real-time bidding (RTB) capabilities are now a must. To answer those needs, the company today unveiled AirDSP, a platform meant to easily connect advertisers to RTB exchanges. Read more: Mobile RTB
Blog
Blog
------------------------------------------------------------ Danish site about electronic cigarettes E Cigarette, Electronic Cigarette and E Cigarettes e cigaret
------------------------------------------------------------ DrugRisks.com drugrisk​ recall ​informat​ion​ drugrisk​ yaz​
------------------------------------------------------------