单击任何服务器控件后,动态添加的div不会保留. [英] Dynamically added div not remain after clicking to any server control.

查看:62
本文介绍了单击任何服务器控件后,动态添加的div不会保留.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过使用javascript在按钮单击上添加了div.

I have added div on button click by using javascript.

<script type="text/javascript" language="javascript">

        function createDiv() {
            var divTag = document.createElement("div");

            divTag.id = "div1";

            divTag.setAttribute("align", "center");
             divTag.style.margin = "0px auto";
            divTag.className = "dynamicDiv";

            divTag.innerHTML = "This HTML Div tag created "  + "using Javascript DOM dynamically.";

            document.body.appendChild(divTag);
        }

    </script>



当我单击任何其他服务器控件时,它消失了.



When i click to any other server control, its disappear. how could i remain it.

推荐答案

没有足够的信息(请参阅我对问题的评论),但是如果出于任何原因重新加载页面,当然,它会加载到其初始状态,就像您没有单击该按钮一样.当您使用ASP.NET时,可以使用会话状态管理在状态上存储信息,以反映以下事实:例如,单击按钮之前已单击该按钮,并且应在事件onload的处理程序中调用其处理程序.

请参阅:
http://msdn.microsoft.com/en-us/library/75x4ha6s.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/z1hkazw7.aspx [ ^ ].

—SA
There is not enough information (please see my comment to the question), but if you re-load the page by whatever reason, of course, it is loaded to its initial state, as if you did not click the button. As you are using ASP.NET, you can use session state management to store the information on the state reflecting the fact that a button was clicked before and its handler should be called in the handler of the event onload (for example).

Please see:
http://msdn.microsoft.com/en-us/library/75x4ha6s.aspx[^],
http://msdn.microsoft.com/en-us/library/z1hkazw7.aspx[^].

—SA


这篇关于单击任何服务器控件后,动态添加的div不会保留.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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