DIV被隐藏后提交的UpdatePanel [英] Div is hidden after submit in UpdatePanel

查看:127
本文介绍了DIV被隐藏后提交的UpdatePanel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 DIV UpdatePanel内,这个DIV显示,当使用点击编辑链接。提交按钮保存此DIV中。现在,当提交按钮都使用的点击是罚款只是该分区将自动隐藏!能见度使用jQuery的显示更改客户端()

I have a div inside an UpdatePanel, this div is shown when a use click on an edit link. The submit buttons to save are inside this div. Now when the use click on the submit button everything is fine except that this div is automatically hidden! the visibility is changed client side using jQuery's show().

为什么的UpdatePanel 隐藏我的 DIV ,即使它是由我显示?我曾试图将 RUNAT =服务器和enableing视图状态,但我得到了同样的结果。

Why is the UpdatePanel hiding my div even though it was shown by me? I have tried to set the runat='server' and enableing viewstate but I am getting the same result.

我怎么就告诉UpdatePanel的离开 div`,因为它是之前提交?

How do I just tell the UpdatePanelto leave thediv` as it is prior to the submit?

下面是表示问题的小型项目

Here is a mini project that shows the problem:

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <div>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                <a href="#" id="edit-link">edit</a>
            </div>
            <div id="edit-div" style="display:none; border: 2px black solid;">
                <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</form>

<script>
    $(document).ready(function(){
        $('#edit-link').on('click', function () {
            $('#edit-div').show();
        });
    });
</script>

在code提交按钮:

The code for the submit button:

protected void Button1_Click(object sender, EventArgs e)
{
    Label1.Text = DateTime.UtcNow.ToString();
}


推荐答案

解决这个问题的最简单的解决办法是: -

The simplest solution to this problem would be: -


  1. 请不要使用jQuery显示编辑-DIV

  2. 编辑-DIV 服务器控件

  3. 转换您的&LT; A HREF =#ID =编辑链接&gt;编辑&LT; / A&GT; &LT; ASP:LinkBut​​ton的&GT; 控制,并在其服务器端单击事件,显示您编辑的div

  1. don't use jQuery to show edit-div
  2. make edit-div a server control
  3. convert your <a href="#" id="edit-link">edit</a> to an <asp:LinkButton> control, and in its server-side click event, show your edit div

的问题是,在UpdatePanel正在恢复原来的状态按照所述标记为页; 编辑-DIV 不是服务器的控制和你显示它通过客户端脚本,在UpdatePanel不知道这一点,并总是会把你返回原来的标记。

The problem is that the UpdatePanel is restoring the original state as per the markup for the page; edit-div is not a server control and you are showing it via client script, the UpdatePanel is unaware of this and will always return you the original markup.

的方式来获得jQuery的发挥不错,在这些情况下的UpdatePanel,但它比上面的简单的解决方案更多地参与。

There are ways to get jQuery to play nice with UpdatePanels in these scenarios, but it is more involved than the simple solution above.

希望有所帮助。

这篇关于DIV被隐藏后提交的UpdatePanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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