Reputation: 69
I'm in need of doing a post back for an asp.net button inside jQuery modal dialog. The markup I have is something like this
<div id="content">
<h1>
Join Our Community</h1>`enter code here`
<hr />
Some Context..
<br />
<br />
Some Context..
<hr />
<br />
<!-- Modal Dialog -->
<a id="tos" href="#serviceterms" title="You must agree with our tems of service.">Click
HERE to Agree to our Terms </a>
<div style="display: none">
<div id="serviceterms" style="width: 440px; height: 250px; overflow: auto;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
<br />
<br />
Some Context..
<br />
<br />
<hr />
<input type="button" value="Yes" onclick="ToS_Agree()" />
<input type="button" value="No" onclick="ToS_NotAgree()" />
</div>
</div>
<br />
<br />
<asp:Button ID="HiddenButton" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:Button ID="SubmitButton" runat="server" Text="Submit Form" Enabled="False" ClientIDMode="Static"
OnClick="SubmitButton_Click" />
<br />
<br />
<asp:Label ID="LabelResult" runat="server" Text=""></asp:Label>
In the jQuery Section, the code is something like
$(document).ready(function () {
$("#tos").fancybox({
'titlePosition': 'inside',
'modal': 'true',enter code here
'transitionIn': 'none',
'transitionOut': 'none'
});
});
function ToS_Agree() {
$('#SubmitButton').removeAttr('disabled');
__doPostBack('<%# HiddenButton.ClientID %>', '')
}
function ToS_NotAgree() {
$('#SubmitButton').attr('disabled', 'disabled');
$.fancybox.close();
}
Problem: When I hit the yes button in the modal dialog, it is posting back correctly. But it directs me to the page_load event body and doesn't go to Button1_Click body. Please help me here. I personally believe that there must be a way to get my desired event body using jQuery.
Upvotes: 0
Views: 8584
Reputation: 13286
An expression with the #
sign is a data-binding expression. It will only evaluate DataBind()
is called. Use the =
sign:
__doPostBack('<%= HiddenButton.UniqueID %>', '')
Upvotes: 3
Reputation: 1490
Instead of:
__doPostBack('<%# HiddenButton.ClientID %>', '')
Do this:
$("#<%=HiddenButton.ClientID%>").click();
It will make the click button clicked and fire your server-side event.
Upvotes: 1