Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to show a confirmation box, which works perfectly with Confirm but doesn't work with my custom message box,

This works,

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {

        LinkButton link = (LinkButton)e.Row.Cells[4].Controls[2];
        if (link != null)
        {
            link.OnClientClick = "return confirm('Do you really want to delete?')";
        }
    }
}

BUT when i put this instead

link.OnClientClick = "ConfirmationBox()";


 function ConfirmationBox() 
    { 
    $.blockUI({ message: $('#question'), css: { width: '275px' } 
    }); 
    }

It shows message box but then it also deleting my record :'(

Still confused ? check this out,

Command field showing messagebox

Edit

<script type="text/javascript">
 $(document).ready(function() { 

 $('#yes').click(function() { 
        $.unblockUI(); 
        return true;
    });

    $('#no').click(function() { 
        $.unblockUI(); 
        return false; 
    }); 
}); 
 </script>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
186 views
Welcome To Ask or Share your Answers For Others

1 Answer

Look at the difference between the two OnClientClick events. The one that works properly returns a value, whereas the one that does not does not.

When the button is clicked, the button action is performed. The on-click action is also performed. However, if the on-click action returns false, the button's action is cancelled. Change

link.OnClientClick = "ConfirmationBox()";

to

link.OnClientClick = "return ConfirmationBox()";

and make ConfirmationBox() return false if the action is not confirmed.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...