<p>The ASP.NET AJAX <strong>ModalPopupExtender</strong> has <code>OnCancelScript</code> and <code>OnOkScript</code> properties, but it doesn't seem to have an <code>OnShowScript</code> property.  I'd like to specify a javascript function to run each time the popup is shown.</p>

<p>In past situations, I set the <code>TargetControlID</code> to a dummy control and provide my own control that first does some JS code and then uses the JS methods to show the popup.  But in this case, I am showing the popup from both client and server side code.</p>

<p>Anyone know of a way to do this?</p>

<p>BTW, I needed this because I have a textbox in the modal that I want to make a TinyMCE editor. But the TinyMCE init script doesn't work on invisible textboxes, so I had to find a way to run it at the time the modal was shown</p>

[{'answer_id': 5488, 'author': 'lomaxx', 'author_id': 493, 'author_profile': 'https://Stackoverflow.com/users/493', 'pm_score': 2, 'selected': False, 'text': '<p>If you are using a button or hyperlink or something to trigger the popup to show, could you also add an additional handler to the onClick event of the trigger which should still fire the modal popup and run the javascript at the same time?</p>\n'}, {'answer_id': 5493, 'author': 'slolife', 'author_id': 698, 'author_profile': 'https://Stackoverflow.com/users/698', 'pm_score': 2, 'selected': False, 'text': '<p>The ModalPopupExtender modifies the button/hyperlink that you tell it to be the "trigger" element. The onclick script I add triggers before the popup is shown.  I want script to fire after the popup is shown.</p>\n\n<p>Also, still leaves me with the problem of when I show the modal from server side.</p>\n'}, {'answer_id': 5500, 'author': 'lomaxx', 'author_id': 493, 'author_profile': 'https://Stackoverflow.com/users/493', 'pm_score': 6, 'selected': True, 'text': "<p>hmmm... I'm <em>pretty sure</em> that there's a shown event for the MPE... this is off the top of my head, but I think you can add an event handler to the shown event on page_load</p>\n\n<pre><code>function pageLoad()\n{\n    var popup = $find('ModalPopupClientID');\n    popup.add_shown(SetFocus);\n}\n\nfunction SetFocus()\n{\n    $get('TriggerClientId').focus();\n}\n</code></pre>\n\n<p>i'm not sure tho if this will help you with calling it from the server side tho</p>\n"}, {'answer_id': 2143771, 'author': 'Brunz', 'author_id': 259688, 'author_profile': 'https://Stackoverflow.com/users/259688', 'pm_score': 2, 'selected': False, 'text': '<p>TinyMCE work on invisible textbox if you hide it with css (display:none;)\nYou make an "onclick" event on TargetControlID, for init TinyMCE, if you use also an updatepanel</p>\n'}, {'answer_id': 2365547, 'author': 'Mircea Dunka', 'author_id': 284646, 'author_profile': 'https://Stackoverflow.com/users/284646', 'pm_score': 4, 'selected': False, 'text': '<p>You should use the <strong>BehaviorID</strong> value <code>mpeBID</code> of your ModalPopupExtender.</p>\n\n<pre><code>function pageLoad() {\n    $find(\'mpeBID\').add_shown(HideMediaPlayer);\n}\n\nfunction HideMediaPlayer() {\n    var divMovie = $get(\'&lt;%=divMovie.ClientID%&gt;\');\n    divMovie.style.display = "none";\n}\n</code></pre>\n'}, {'answer_id': 9529512, 'author': 'John Ward', 'author_id': 1244536, 'author_profile': 'https://Stackoverflow.com/users/1244536', 'pm_score': 4, 'selected': False, 'text': "<p>Here's a simple way to do it in markup:</p>\n<pre><code>&lt;ajaxToolkit:ModalPopupExtender \n    ID=&quot;ModalPopupExtender2&quot; runat=&quot;server&quot; \n    TargetControlID=&quot;lnk_OpenGame&quot; \n    PopupControlID=&quot;Panel1&quot; \n    BehaviorID=&quot;SilverPracticeBehaviorID&quot;  &gt;\n    &lt;Animations&gt;\n        &lt;OnShown&gt;\n             &lt;ScriptAction Script=&quot;InitializeGame();&quot; /&gt;  \n        &lt;/OnShown&gt;\n    &lt;/Animations&gt;                \n&lt;/ajaxToolkit:ModalPopupExtender&gt;\n</code></pre>\n"}, {'answer_id': 15915119, 'author': 'Mormon SUD', 'author_id': 2241412, 'author_profile': 'https://Stackoverflow.com/users/2241412', 'pm_score': 2, 'selected': False, 'text': "<pre><code>var launch = false;\n\nfunction launchModal() {\n    launch = true;\n}\n\nfunction pageLoad() {\n    if (launch) {\n          var ModalPedimento = $find('ModalPopupExtender_Pedimento');\n          ModalPedimento.show();\n          ModalPedimento.add_shown(SetFocus);\n    }\n}\n\nfunction SetFocus() {\n    $get('TriggerClientId').focus();\n}\n</code></pre>\n"}, {'answer_id': 15932547, 'author': 'Mormon SUD', 'author_id': 2241412, 'author_profile': 'https://Stackoverflow.com/users/2241412', 'pm_score': 2, 'selected': False, 'text': '<p>For two modal forms:</p>\n\n<pre><code>var launch = false;\nvar NameObject = \'\';\n\nfunction launchModal(ModalPopupExtender) {\n    launch = true;\n    NameObject = ModalPopupExtender;\n}\n\nfunction pageLoad() {\n    if (launch) {\n        var ModalObject = $find(NameObject);\n        ModalObject.show();\n        ModalObject.add_shown(SetFocus);\n                }\n} \n\nfunction SetFocus() {\n    $get(\'TriggerClientId\').focus();\n}\n</code></pre>\n\n<p>Server side: behand</p>\n\n<pre><code>protected void btnNuevo_Click(object sender, EventArgs e)\n{\n    //Para recuperar el formulario modal desde el lado del sercidor\n    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", "&lt;script&gt;launchModal(\'" + ModalPopupExtender_Factura.ID.ToString() + "\');&lt;/script&gt;", false);\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/5482', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/698/']