Note that there are some explanatory texts on larger screens.

plurals
  1. POPlacing ajax ModalPopupExtender inside User control
    text
    copied!<p>I use an ajax ModalPopupExtender on many pages to display confirmation dialog.</p> <p>So i would like to reuse same code on all pages by placing it in a use control. But I'm not sure it it possible to access this user control from a javascript (I don't want server side operations).</p> <p>This is the code that is responsible for popup display, that i want to place inside user control:</p> <pre><code>&lt;script language="javascript" type="text/javascript"&gt; var _source; var _popup; var _btn; var _div; function showConfirm(source, btnID, theDiv) { this._source = source; this._btn = btnID; this._div = theDiv; document.getElementById(btnID).click(); document.getElementById(theDiv).style.visibility = 'visible'; } function okClick() { document.getElementById(_div).style.visibility = 'hidden'; __doPostBack(this._source.name, ''); } function cancelClick() { document.getElementById(_div).style.visibility = 'hidden'; this._source = null; } &lt;/script&gt; &lt;cc1:ModalPopupExtender ID="modal" runat="server" TargetControlID="theButton" PopupControlID="div" OkControlID="btnOk" OnOkScript="okClick();" CancelControlID="btnNo" OnCancelScript="cancelClick();" BackgroundCssClass="modalBackground" /&gt; &lt;div id="div" runat="server" align="center" class="confirm" style="display: none"&gt; &lt;img align="absmiddle" src="../images/warning.jpg" /&gt;Are you sure you want to delete this item? &lt;/br&gt; &lt;asp:Button ID="btnOk" runat="server" Text="Yes" Width="50px" /&gt; &lt;asp:Button ID="btnNo" runat="server" Text="No" Width="50px" /&gt; &lt;/div&gt; </code></pre> <p>And on the "hosting" page, I want to assign JS to a buttons that will trigger the popup: This is the code that i have now (and should be adopted to the user control):</p> <pre><code>string s = string.Format("showConfirm(this,'{0}','{1}');return false;", theButton.ClientID, div.ClientID); btn.OnClientClick = s; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload