删除div中的代码. [英] Deleting div's in code behind.

查看:56
本文介绍了删除div中的代码.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以从ASP.Net后面的代码中删除div(html元素).

即:if(blah == true){div1.remove} else {div2.remove}

Is there any way I can remove a div (html element) from the code behind in ASP.Net.

ie: if (blah == true) { div1.remove } else { div2.remove }

推荐答案

没有要删除的内容,如div(或其他任何内容)服务器端不存在DOM元素),而仅在HTTP响应中生成HTML代码.因此,DOM对象当时不存在,仅在接收到HTTP响应并对其进行处理后才在客户端创建. 删除"仅表示在下一次回发中不生成这些元素,您可以在类System.Web.HttpResponse http://msdn.microsoft.com/en-us/library/ms178472%28v = vs.100%29.aspx [ ^ ].

—SA
There is nothing to remove, as div (or any DOM element) does not exist on the server side, which just generates HTML code in HTTP response. So, DOM object does not exist at that time, it is created only on client side after it receives the HTTP response and processes it. "Removal" would simply mean not generating those elements in next postback, which you can do in the class System.Web.HttpResponse, http://msdn.microsoft.com/en-us/library/system.web.httpresponse.aspx[^].

What you can do it to program deletion of the element in JavaScript, depending on some condition. If this is not clear so far, you can try to describe the behavior you want to achieve. In the meanwhile, it would be good for your to review the ASP.NET page life cycle:
http://msdn.microsoft.com/en-us/library/ms178472%28v=vs.100%29.aspx[^].

—SA



尝试这样可以解决您的问题

try like this will solve your problem
ClientScript.RegisterStartupScript(this.GetType(), "remove", "<script>


('#div1').remove();</script>");
('#div1').remove();</script>");


这篇关于删除div中的代码.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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