2

sorry if my english is poor.

I've a question, i think that the problem is my poor knowledge of javascript but.. i know that you can help me about this.

i've a page with an imagebutton, i use this for delete data and i need a confirmation dialog box. Alertify is pretty, i use altertify alert in server side like this:

string myScript2 = "alertify.error('message.')";
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), 
                Guid.NewGuid().ToString(), myScript2, true);
return; 

and work fine!

but i don't understand how to use alertify.confirm.

for example i've used

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="../../js/alertify.min.js"></script>
    <!-- include the core styles -->
<link rel="stylesheet" href="../../js/alertify.core.css" />
    <!-- include a theme, can be included into the core instead of 2 separate files -->
<link rel="stylesheet" href="../../js/alertify.default.css" />
<script type="text/javascript">
        $("#btElimina").on('click', function () {
            alertify.confirm("This is a confirm dialog", function (e) {
                if (e) {
                    alertify.success("You've clicked OK");
                } else {
                    alertify.error("You've clicked Cancel");
                }
            });
            return false;
        });
    </script>

but nothing to do...i can't use onclientclick because alertify is a non-blocking instead a modal windows... can you help me to understand? not to write code for me, but, to understand and make me viable thank you

Henry

3 Answers 3

1

Replace alertify.success("You've clicked OK"); with return true; and alertify.error("You've clicked Cancel"); with return false;

Also change this:

$("#btElimina").on('click', function () {

to this:

$("#<%=btElimina.ClientID%>").on('click', return function () {
Sign up to request clarification or add additional context in comments.

7 Comments

Thank you, now i have correct the code. Now when i click the imagebutton, this button <asp:ImageButton ID="btElimina" ImageUrl="~/images/Elimina.png" runat="server" /> the page refresh but doesn't do nothing. i don't see a confirm dialog box. But thank you, i understand with you answer that i can take a response like onclientclick
please confirm what is the id of imagebutton on render in html. I think it will not be btElimina. check it.
yes, in this post i write btElimina because the real name on render in html is long. and is ctl00_ContentPlaceHolder1_btElimina
yes,therefore your js code is not firing. see the update answer
yes, and i dont understand why! i have some js code in this page and work fine! for example, open page in popup dialog ecc..
|
1

I used this and it is working:

My button is :

<asp:ImageButton ToolTip="Çıkış" ID="ImageButton1" ImageUrl="Image/Exit.png" runat="server"  OnClick="btnLogout_Click" />

My script is:

<script type="text/javascript">
    $("#ImageButton1").on('click', function () {
        alertify.confirm("This is a confirm dialog", function (e) {
            if (e) {
                alertify.success("You've clicked OK");

                __doPostBack("<%=ImageButton1.UniqueID%>", "");
            } else {
                alertify.error("You've clicked Cancel");
            }
        });
        return false;
    });
</script>

Here when i clicked "cancel" button returns false and doing nothing but when you clicked ok button i am doing postback for related button and you can write your own code in server side

protected void btnLogout_Click(object sender, EventArgs e)
        {
            Session.RemoveAll();
            Response.Redirect("~/Login.aspx");
            ...
        } 

Comments

0

I can't comment on the last comment below as I don't have 50 reputation, so I'm posting an answer simply to elaborate on Ratna's answer.

As per Ratna's answer, you should use server tags to refer to ASP.Net controls (controls with runat="server") to ensure that you get the control regardless of what ASP.Net renames the control to.

So to reiterate Ratna's answer:

Instead of

$('#btElimina').on(..

use

$('#<%= btElimina.ClientID %>').on(..

to make sure that you get the correct clientside control id in your jQuery script.

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.