按钮回发后(服务器端)jquery对话框移动到页面顶部

时间:2014-02-04 19:48:15

标签: javascript jquery asp.net

我有一个打开的jquery对话框。在它上面是AutoPostback设置为true的一些服务器端下拉列表,因为它们在回发后级联并填充其他下拉列表。通过使用隐藏字段并将其设置为1(如果我需要保持对话框打开)或者如果我想关闭它,则保持我的对话框保持打开状态。

继承jquery测试以查看隐藏字段值:

 if ($("#MainContent_hdnOpenContactCompany").val() === "1") {
                $("#dialogContactCompany").dialog("open");
            } else {
                $("#dialogContactCompany").hide();
            }

所以我的问题不在于我没有打开对话框,我的问题是当我向下滚动页面然后打开一个对话框时,我做回发的那一刻对话框移动到页面顶部。因此,除非他/她滚动到顶部,否则用户无法看到它。

我尝试添加这个,(http://www.cleancode.co.nz/blog/240/jquery-dialog-position-problem-web-form-postback),但我相信作者有一个设定的宽度...但这对我不起作用。

 //Company dialog
            var pos = new Array();
            pos[0] = ($(window).width() - 880) / 2 +
                       parseInt(theForm.elements['__SCROLLPOSITIONX'].value);
            pos[1] = 100 + parseInt(theForm.elements['__SCROLLPOSITIONY'].value);

            $("#dialogContactCompany").hide();
            $("#dialogContactCompany").dialog({
                autoOpen: false,
                appendTo: "form:first",
                position: pos,
                width: 880,
                height: 'auto',
                modal: true,
                open: function (event, ui) {
                    $('#dialogContactCompany').css('overflow', 'hidden'); //this line does the actual hiding
                },
                close: function (event, ui) {
                    //if someone x's out (Closes the dialog) we better make sure we
                    //set the hidden field to 0 so that the dialog doesn't open up again on post back
                    $("#MainContent_hdnOpenContactCompany").val("0");
                }

            });

主要是pos信息来维持一个位置,但这也不起作用。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

最后得到了这个我们必须使用document.scroll。 这是一篇很棒的文章:http://jadendreamer.wordpress.com/2013/04/24/jquery-tutorial-scroll-ui-dialog-boxes-with-the-page-as-it-scrolls/

相关问题