如何避免对ASP按钮单击事件回传 [英] How to avoid postback for the ASP button click event

查看:211
本文介绍了如何避免对ASP按钮单击事件回传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jQuery的多选在我使用的云服务器端和填充另一DropDownList的值按钮单击事件。根据在下拉列表中选择检查它填充值中的其他DropDownList中。

I am using the jQuery multiselect in that I am using button click event which goes the server side and the populates the values on the other dropdownlist. Based on the checked selection in the drop down list it populate the values in the other dropdownlist.

问题:

有关例如:在第一个jQuery的多选下拉如果我选择3个值,并关闭基于这三个值检查细节在其他jQuery的多选的DropDownList牵强,但最后的检查值只有被选中,被保留的DropDownList。我想这是因为按钮点击事件的发生是一个异步回发,其值是不保留。是他们,在按钮单击事件回发任何选项prevent但是点击应称为则只值将被保留。

For eg: in the first jQuery multiselect dropdown if I select 3 values and close the dropdownlist based on these three values checked the details are fetched in the other jQuery multiselect dropdownlist but the last checked value only is checked and that is retaining. I think it is because of button click event it occurs a asynchronous postback and the values is not retaining. Is their any option to prevent that postback in the button click event but the click should be called then only the values will be retained.

对于这些我附上了截屏:

For these I am attaching the screen shot:

根据它在其他的dropdownlist加载的三个值,但它示出了1选择了是默认选择

Based on that three values it is loaded in the other dropdownlist but it is shows "1 selected" that is default "Select".

但是,第二个DropDownList的,我可以能够得到在第一下拉列表中选中的值:

But the second dropdownlist I can able to get the values that is checked in the first dropdown list:

这是我的javascript:

this is my javascript:

  $(document).ready(function () {

            $('.department').multiselect({
                show: ["bounce", 5], hide: ["blind", 1],

                close: function () {
                    debugger;
                    var values = new Array();

                    $(this).multiselect("getChecked").each(function (index, item) {
                        values.push($(item).val());
                    });
                    $("input[id*=selectedValues]").val(values.join(","));
                    document.getElementById("<%=hdnDepartment.ClientID %>").value = values;
                    if (document.getElementById("<%=hdnDepartment.ClientID %>").value != "") {
                        **$("#<%=Button1.ClientID %>")[0].click();**

                    }
                }

            })
        .multiselectfilter();
        });

protected void Button1_Click(object sender, EventArgs e)
    {
        Populate();
    }

纠正我,如果我错了......

Correct me if i am wrong...

推荐答案

您可以使用的OnClientClick,并返回假意或真心按您的要求。
当的OnClientClick返回true回传否则将不发生回发

You can use OnClientClick and return false or true as per your requirement. When OnClientClick return true postback will occur else no postback

这篇关于如何避免对ASP按钮单击事件回传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆