简体   繁体   English

Div加载并在asp.net PageLoad上消失

[英]Div loads and disappears on asp.net PageLoad

I have a div that I want to appear based on user input (works), however this div will appear and then hide itself on page load, because the javascript simply tells this Div to appear based on user input , and the input is defaulted to the option which causes the div to hide. 我有一个要根据用户输入(工作)显示的div,但是此div会出现,然后在页面加载时自行隐藏,因为javascript只是告诉该Div根据用户输入来显示,并且输入默认为导致div隐藏的选项。 I am including the code 我包括代码

<script type="text/javascript">

    function HideUnhide() {
        if (!$("#RadioButtonInput").attr("checked")) {
            $("#hideableDiv").fadeOut(200);
        } else {
            $("#hideableDiv").fadeIn(200);
        }
    }

    $(function () {
        //initial hide/unhide
        HideUnhide();
        //click triggered hide/unhide
        $(".RadioButtonID > input").click(
            function (event) {
                alert('click');
                HideUnhide();
            }
        );
    });

The RadioButton is binded to a SQL value in the website which stores session data, so it can't just "always be hidden" when the page loads, but it's visually annoying to watch this div be present and then disappear based on the data binding. RadioButton绑定到存储会话数据的网站中的SQL值,因此在页面加载时,它不能只是“总是被隐藏”,但是基于数据绑定,看到此div存在然后消失就在视觉上很烦人。

How can I fix this? 我怎样才能解决这个问题?

在为div编写HTML的服务器端代码中,测试SQL值(如果应将其隐藏),然后向HTML添加style="display:none"的style属性。

You will have to set the initial visibility on the server side. 您将必须在服务器端设置初始可见性。 Set the div to runat="server" , and right after you set the Checked property of the button, do this: 将div设置为runat="server" ,并在设置按钮的Checked属性后立即执行以下操作:

myDiv.Style.Add("display", (myButton.Checked ? "block" : "none"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM