Use the confirm of jquery-easyui in Asp.net

Source: Internet
Author: User

Jquery-easyui provides simplified encapsulation. This allows us to implement web UI more conveniently.

The confirm method is described as follows in its sample:

function confirm1(){
    $.messager.confirm('My Title', 'Are you confirm this?', function(r){
        if (r){
            alert('confirmed:'+r);
            location.href = 'http://www.google.com';
        }
    });
}

For ASP. NET Server-side controls such as linkbutton, we often use

Onclientclick = "Return confirm ('Are you sure you want to delete? ');"

However, if we want to unify the UI, we want to use the confirm of jquery-easyui, but we cannot simply encapsulate

        function Confirm(msg) {
            $.messager.confirm('Confirmed', msg, function(r) {
                return r;
            });            
        }

Then, call:

Onclientclick = "Return confirm ('Are you sure you want to delete? '); "// Note the case sensitivity. This confirm is not another confirm.

We know that what linkbutton actually triggers a business is to use JavaScript Execution in the href attribute.

<A plain ="true" icon="icon-remove" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$gv$ctl08$LinkButton1','')" onclick="Return confirm ('passed? ');" class="easyui-linkbutton" id="ctl00_ContentPlaceHolder1_gv_ctl08_LinkButton1"> Delete </a>

Therefore, we need to change our thinking and encapsulate it as follows.

// Confirmation box for Asp.net server controls
        function Confirm(msg, control) {
            $.messager.confirm('Confirmed', msg, function(r) {
                if (r) {
                    eval(control.toString().slice(11));// Cut off javascript: and execute
                }
            });
            return false;            
        }

Use return confirm ('OK? ', This );

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.