如何使用jquery prevent回传 [英] how to prevent postback using jquery

查看:134
本文介绍了如何使用jquery prevent回传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$(document).ready(function () {
    $("#Div_1").show();
    $("#Div_2").hide();

    $('#Buttion1').click(function () {
        $("#Div_1").hide();
        $("#Div_2").show();
    });
});

在上面的code,而装载工作,但是当点击(Buttion1是ASP.Net服务器按钮)按钮Div_2没有炫耀和Div_1没有隐瞒过

in the above code, while loading is working but when click (Buttion1 is ASP.Net Server button) on button Div_2 not showing off and Div_1 not hiding off

推荐答案

试试这个

    $(document).ready(function () {
        $("#Div_1").show();
        $("#Div_2").hide();

        $('#Buttion1').click(function () {
            $("#Div_1").hide();
            $("#Div_2").show();
            return false;
        });

    });

<asp:UpdatePanel runat="server">
    <ContentTemplate>
        <asp:Button Text="text" ID="Buttion1" OnClientClick="hideshow();" runat="server"
            OnClick="Buttion1_Click" />
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Buttion1" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>
<div id="Div_1">
</div>
<div id="Div_2">
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $(document).ready(function () {
            $("#Div_1").show();
            $("#Div_2").hide();
        });

    })
    function hideshow() {
        $("#Div_1").hide();
        $("#Div_2").show();
        return true;
    }
</script>

服务器端code

server side code

    protected void Buttion1_Click(object sender, EventArgs e) { 
        //server side code
    }

请注意:

1)你的两个分区必须出方的UpdatePanel。

1)your two div must be out side updatepanel.

2)你的隐藏显示的功能绝不能undefined.Place功能在页面

2)your hideshow function must not be undefined.Place function on at the en of the page

3)按钮点击客户端调用隐藏显示功能,返回true

3)on button client click call hideshow function which return true

4)后的JavaScript函数返回true..it无二的服务器端事件

4) after javascript function return true..it goes for the server side event

这篇关于如何使用jquery prevent回传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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