Conditional ConfirmButtonExtender
<p>I am trying to bypass the ConfirmButtonExtender depending on the value of another field in the page.</p>

<p>Basically, when a user click on my "Cancel" button, I normally display a modalpopup using the confirmbuttonextender and the modalpopupextender to display a dialog box confirming that they wish to cancel any changes they have made and return to the prior screen.  If they click Yes, the button's onclick event fires which calls some code in the codebehind and redirects the user to another page.  If they click no, it just returns to the same page, with no changes.</p>

<p>However, in some situations, I know that my user is unable to perform any edits (they aren't allowed to) and for those users, I don't want to display the "Are you sure you want to leave you will loose any changes" dialog box.</p>

<p>I've set a hidden checkbox field named "cbAllowEdit" to indicate whether the user is allowed to edit the fields or not.</p>

<p>I was trying to use the technique found at <a href="http://vincexu.blogspot.com/2008/12/conditionally-display.html" rel="nofollow">link text</a> to get this working but it just doesn't even seem to be firing the button's onclientclick event at all.</p>

<p>Here is my code.</p>

<p>ASPX &amp; Javascript</p>

<pre><code>    &lt;asp:CheckBox ID="cbAllowEdit" runat="server" Checked="true" /&gt;
         &lt;asp:Button ID="btnCancel" runat="server" CausesValidation="false" 
    OnClick="btnCancel_Click" Text="Cancel" OnClientClick="disableSubmit();return false;"  /&gt;
&lt;ajaxToolKit:ConfirmButtonExtender ID="ConfirmButtonExtenderbtnCancel" 
    runat="server" DisplayModalPopupID="ModalPopupExtenderbtnCancel" 
    TargetControlID="btnCancel" BehaviorID="ConfirmButtonExtenderbtnCancel" /&gt;
&lt;ajaxToolKit:ModalPopupExtender ID="ModalPopupExtenderbtnCancel" runat="server" 
    BackgroundCssClass="modalBackground" CancelControlID="btnCancelCancel" 
    OkControlID="btnConfirmCancel" PopupControlID="ConfirmCancelPanel" 
    TargetControlID="btnCancel" /&gt;
&lt;asp:Panel ID="ConfirmCancelPanel" runat="server" CssClass="modalWindow" 
            Height="200" Width="450"&gt;
            &lt;p class="confirmMessage"&gt;
                Are you sure you want to navigate away from this record?
            &lt;/p&gt;
            &lt;div align="center"&gt;
                &lt;p class="feedbackError"&gt;If you have made any changes to the record since the last time
                you saved, they will be lost.&lt;/p&gt;
                &lt;asp:Button ID="btnConfirmCancel" runat="server" Text="Yes" Width="75" /&gt;
                &lt;asp:Button ID="btnCancelCancel" runat="server" Text="No" Width="75" /&gt;
            &lt;/div&gt;
        &lt;/asp:Panel&gt;
        &lt;script type="text/javascript"&gt;
            function disableSubmit() {
                if (document.getElementById('&lt;%= cbAllowEdit.ClientID %&gt;').checked) {
                    return checkSubmit();
                }
                else {
                    return true;
                }
            }

            function checkSubmit() {

                var confirmButton = $find('ConfirmButtonExtenderbtnCancel');

                confirmButton._displayConfirmDialog();

            }
        &lt;/script&gt;
</code></pre>

<p>Code behind:</p>

<pre><code>/// &lt;summary&gt;
        /// Runs when the btnCancel button is clicked.
        /// &lt;/summary&gt;
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Page.Response.Redirect("~/Searches/LookupCode/Default.aspx");
        }
</code></pre>

<p>any ideas on what I am doing wrong?</p>
