ASP.NET,jQuery UI对话框在页面中显示1-2秒 [英] ASP.NET,jQuery UI Dialog showing in page for 1-2 seconds

查看:56
本文介绍了ASP.NET,jQuery UI对话框在页面中显示1-2秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET页面,我将在该页面中检查用户是否在页面加载中登录了系统(通过检查会话值),如果未登录,它将显示一个jQueryUI对话框进行登录./p>

我的ASPX页面的head标签中包含这些脚本

<style type="text/css">
    body { font-size: 62.5%; }
    label, input { display:block; }
    input.text { margin-bottom:12px; width:95%; padding: .4em; }
    fieldset { padding:0; border:0; margin-top:25px; }
    h1 { font-size: 1.2em; margin: .6em 0; }
    div#users-contain {  width: 350px; margin: 20px 0; }
    div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
    div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
    .ui-button { outline: 0; margin:0; padding: .4em 1em .5em; text-decoration:none;  !important; cursor:pointer; position: relative; text-align: center; }
    .ui-dialog .ui-state-highlight, .ui-dialog .ui-state-error { padding: .3em;  }


</style>
<script type="text/javascript">
$(function() {

    var name = $("#name"),
        email = $("#email"),
        password = $("#password"),
        allFields = $([]).add(name).add(email).add(password),
        tips = $("#validateTips");

    function updateTips(t) {
        tips.text(t).effect("highlight",{},1500);
    }


    function checkRegexp(o,regexp,n) {

        if ( !( regexp.test( o.val() ) ) ) {
            o.addClass('ui-state-error');
            updateTips(n);
            return false;
        } else {
            return true;
        }

    }

    $("#dialog").dialog({
        bgiframe: true,
        autoOpen: false,
        height: 250,
        modal: true,
        buttons: {
                Cancel: function() {
                $(this).dialog('close');
                },                                  
                NewUser: function() {
                 $(this).dialog('close');
                 window.location.href="Register.aspx";
                },
                'Sign in': function() {
                var bValid = true;
                allFields.removeClass('ui-state-error');


                bValid=true;
                isValidationFails=false;
                if (bValid)
                {              
                                        // Go to another page

                    } 
                }
            }
        },
        close: function() {
            allFields.val('').removeClass('ui-state-error');
        }
    });



    $('#create-user').click(function() {
         $(this).dialog('close');
         window.location.href="Register.aspx"
    })
    .hover(
        function(){ 
            $(this).addClass("ui-state-hover"); 
        },
        function(){ 
            $(this).removeClass("ui-state-hover"); 
        }
    ).mousedown(function(){
        $(this).addClass("ui-state-active"); 
    })
    .mouseup(function(){
            $(this).removeClass("ui-state-active");
    });

//});
var isAuthenticated = $("#isAuthenticated").val();
if (isAuthenticated && isAuthenticated == "false")
{
  $("#dialog").dialog("open");
}

});

</script>

服务器辅助代码(在Page_Load中)

 if (Session["trCustomerId"] != null)
        {
            Response.Write("Logged in user");
            ClientScript.RegisterHiddenField("isAuthenticated", "true");
        }
        else
        {
            ClientScript.RegisterHiddenField("isAuthenticated", "false");
        }

该程序现在可以正常工作了.但是问题是页面加载时,它在屏幕上显示1-2秒钟的UIDialog div,然后消失.我不想这样显示.有人可以告诉我如何解决这个问题吗?

解决方案

尝试将对话框标记的样式设置为display:none;

#dialog{
   display: none;
}

然后,如果dialog.open不能为您显示,则可以显示它.

$('#dialog').show()

I have an ASP.NET page where i will check whether the user has logged in to the system (by checking the session value) in the page load and if not logged in,it will show a jQueryUI dialog for login.

My ASPX page contains these script in the head tag

<style type="text/css">
    body { font-size: 62.5%; }
    label, input { display:block; }
    input.text { margin-bottom:12px; width:95%; padding: .4em; }
    fieldset { padding:0; border:0; margin-top:25px; }
    h1 { font-size: 1.2em; margin: .6em 0; }
    div#users-contain {  width: 350px; margin: 20px 0; }
    div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
    div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
    .ui-button { outline: 0; margin:0; padding: .4em 1em .5em; text-decoration:none;  !important; cursor:pointer; position: relative; text-align: center; }
    .ui-dialog .ui-state-highlight, .ui-dialog .ui-state-error { padding: .3em;  }


</style>
<script type="text/javascript">
$(function() {

    var name = $("#name"),
        email = $("#email"),
        password = $("#password"),
        allFields = $([]).add(name).add(email).add(password),
        tips = $("#validateTips");

    function updateTips(t) {
        tips.text(t).effect("highlight",{},1500);
    }


    function checkRegexp(o,regexp,n) {

        if ( !( regexp.test( o.val() ) ) ) {
            o.addClass('ui-state-error');
            updateTips(n);
            return false;
        } else {
            return true;
        }

    }

    $("#dialog").dialog({
        bgiframe: true,
        autoOpen: false,
        height: 250,
        modal: true,
        buttons: {
                Cancel: function() {
                $(this).dialog('close');
                },                                  
                NewUser: function() {
                 $(this).dialog('close');
                 window.location.href="Register.aspx";
                },
                'Sign in': function() {
                var bValid = true;
                allFields.removeClass('ui-state-error');


                bValid=true;
                isValidationFails=false;
                if (bValid)
                {              
                                        // Go to another page

                    } 
                }
            }
        },
        close: function() {
            allFields.val('').removeClass('ui-state-error');
        }
    });



    $('#create-user').click(function() {
         $(this).dialog('close');
         window.location.href="Register.aspx"
    })
    .hover(
        function(){ 
            $(this).addClass("ui-state-hover"); 
        },
        function(){ 
            $(this).removeClass("ui-state-hover"); 
        }
    ).mousedown(function(){
        $(this).addClass("ui-state-active"); 
    })
    .mouseup(function(){
            $(this).removeClass("ui-state-active");
    });

//});
var isAuthenticated = $("#isAuthenticated").val();
if (isAuthenticated && isAuthenticated == "false")
{
  $("#dialog").dialog("open");
}

});

</script>

SErver side code (in Page_Load)

 if (Session["trCustomerId"] != null)
        {
            Response.Write("Logged in user");
            ClientScript.RegisterHiddenField("isAuthenticated", "true");
        }
        else
        {
            ClientScript.RegisterHiddenField("isAuthenticated", "false");
        }

The program is working fine now . But the problem is when the page is loading,it is showing the UIDialog div for 1-2 seconds in the screen and then disappearing. I dont want to show like this.Can any one tell me how to solve this ?

解决方案

Try setting the style on your dialog markup to display:none;

#dialog{
   display: none;
}

You can then show it if the dialog.open doesn't do it for you.

$('#dialog').show()

这篇关于ASP.NET,jQuery UI对话框在页面中显示1-2秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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