1

This was my precedent implementation:

In example.aspx:

<asp:Button ID="rejectButton" runat="server" Text="REJECT" OnClick="OnRejectButtonClick"/>

and in example.aspx.cs:

protected void OnRejectButtonClick(object sender, EventArgs e)
{
    // a lot of stuff...
    rejecter();
}

... this works.

Now I need a dialog for confirm the rejecting. Now my code is:

In example.aspx:

<asp:Button ID="rejectButton" runat="server" Text="REJECT" OnClientClick="return openDialog();"/>

<div id="dialog" title="Seleziona causa">
    <p>... bla bla...</p>
</div>

<script>
    $(function () {
        $("#dialog").dialog({ autoOpen: false, modal: true, show: "blind", hide: "blind",
            buttons: {
                "Okay": function () {
                    OnRejectButtonClick; // DOESN'T WORK!
                    $(this).dialog("close");

                },
                "Annulla": function () {
                    $(this).dialog("close");
                }
            }
        });
    });

    function openDialog() {
        $("#dialog").dialog("open");
        return false;
    }
</script>

and example.aspx.cs is not changed.

But after this changing, the call to OnRejectButtonClick event doesn't fire anymore. How can I fix this?

3 Answers 3

2

If you don't want to use jquery you can use this :

__doPostBack('<%= rejectButton.UniqueID %>', "");

so your code will be like this :

   $(function () {
        $("#dialog").dialog({ autoOpen: false, modal: true, show: "blind", hide: "blind",
            buttons: {
                "Okay": function () {
                    __doPostBack('<%= rejectButton.UniqueID %>', "");
                    $(this).dialog("close");

                },
                "Annulla": function () {
                    $(this).dialog("close");
                }
            }
        });
    });
Sign up to request clarification or add additional context in comments.

Comments

2

You need to call it with jquery.

//before you click the button you should set a global variable
serverEx = true;
$("#rejectButton").click();

And in your OnClientSciprt method for the reject button openDialog

function openDialog() {

    if(serverEx)
       return true;

    $("#dialog").dialog("open");
    return false;
}

Add ClientIDMode="Static" to the button like Chris Davis said.

2 Comments

Note that you will need ClientIDMode="Static" on the tag for this to work, as it's an ASP tag and the ID will be generated before transforming into HTML, resulting in a slightly different ID.
@ChrisDavis yes I forgot about that.
0

You could try something like this:

__doPostBack('rejectButton','OnClick'); 

to actually perform the asp.net action.

Comments

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.