0

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()" />&nbsp;&nbsp;
                <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.

1

2 Answers 2

3

An expression with the # sign is a data-binding expression. It will only evaluate DataBind() is called. Use the = sign:

__doPostBack('<%= HiddenButton.UniqueID %>', '')
Sign up to request clarification or add additional context in comments.

7 Comments

This is common mistake to use control's ClientID for __doPostBack function parameter. Use UniqueID property instead and you'll save a lot of time of debugging.
thanks for your concern :) this is helpful plz also help me in the actual problem i have posted ..thanks in Advance
the problem is, when i hit the Yes Button i go inside Page_load Function body but after that it doesn't get me to my OnLCick Event .. like other asp.net controls do on postabck..
do u mean unique id like __doPostBack('<%= HiddenButton.UniqueID %>', '') (i m currently doing in this way) ? or is there any other way to use unique id .
Yes I mean this. BTW, how do you make your button hidden?
|
1

Instead of:

__doPostBack('<%# HiddenButton.ClientID %>', '')

Do this:

$("#<%=HiddenButton.ClientID%>").click();

It will make the click button clicked and fire your server-side event.

1 Comment

thanks for your replay. :) well this solution doesn't work for me.. and there are posts according to which .click() is not compatible with all browsers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.