Hi,
I'm trying to get the JQuery jqModal extension to work as a confirm box, as per the example given on the jqModal website ( http://dev.iceburg.net/jquery/jqModal/ ), and incoprate this function into a dotnet usercontrol so I can re-use it over the website.
This is the code I've written so far. The control has a TriggerID property which is the ID of the linkbutton control that will fire the function. Because it's a linkbutton, I figured that on a "yes" click in the confirm I could simple use eval() on the href attribute of the linkbutton to re-create the postback, since dotnet creates the control with a javascript call to __dopostback in the href.
<div id="policypopup" runat="server" class="policypopup">
<h2>
<asp:Label ID="LblTitle" runat="server">My Title</asp:Label>
</h2>
<div class="jqmConfirmContent">
<p class="jqmConfirmMsg"></p>
<p>Continue?</p>
</div>
<input type="submit" value="no" />
<input type="submit" value="yes" />
</div>
<script type="text/javascript">
function confirm(msg, callback) {
$('#<%= policypopup.clientId %>')
.jqmShow()
.find('p.jqmConfirmMsg')
.html(msg)
.end()
.find(':submit:visible')
.click(function () {
if (this.value == 'yes') {
eval(callback);
}
$('#<%= policypopup.clientId %>').jqmHide();
});
}
$().ready(function () {
$('#<%= policypopup.clientId %>').jqm({ overlay: 88, modal: true, trigger: false });
$('#<%= Me.TriggerID %>').click(function () {
confirm('Are you sure you want to delete?:', this.href);
return false;
});
});
</script>
However I have two problems with this script as is: 1) The eval of the href is not causing a postback. I've checked to make sure that the value of href is being passed correctly (it is), and that eval will correctly evaluate simple functions prefixed with javascript: (it will). So I'm at a loss to know why it won't work as written. 2) After firing the confirm box once, it will not fire again. I've tried placing the initialisation code into a separate function and calling it again from confirm() but no dice. Is there any way I can get this to keep on firing up confirm boxes without having to cause a postback?
EDIT: Further investigation is suggesting this may be related to the controls in question being in an updatepanel. But that hasn't helped me solve the problem thus far.
Cheers, Matt