在显示条件asp.net一个div [英] Show a div in asp.net on condition
问题描述
是否可以显示/ notshow在asp.net取决于如果cookie被设置或没有一个div?
注:在div是在asp.net中调用JavaScript的HTML表单
在这里,code在asp.net
< ASP:内容ID =内容2ContentPlaceHolderID =ContentPlaceHolder2=服务器>
<脚本类型=文/ JavaScript的>
$(文件)。就绪(函数(){$('#'<%= webform.ClientID%方式>)负载('popup.html');
< / SCRIPT>< DIV ID =表单=服务器>
< / DIV>
< / ASP:内容>
和在code背后:
保护无效的Page_Load(对象发件人,EventArgs的发送)
{webform.Visible = TRUE;}
请注意,该表单是可见的,当code是:(没有什么是code后面)
<脚本类型=文/ JavaScript的> $(文件)。就绪(函数(){$('#表单')负载('popup.html');})
< / SCRIPT>
< DIV ID =表单>
< / DIV>
< / ASP:内容>
的目的是使这种可见或不取决于如果饼干已经设置或没有。
我已经测试的形式(HTML)被设定饼干(通过表单的JavaScript)
这里的逻辑,你可以试试。
-
加入让你的DIV服务器控件
=服务器
属性 -
也有一个
ID
属性的DIV标签 -
从code设置此DIV的知名度背后基于Cookie值
例如。
标记code
< DIV ID =MyDiv=服务器>< / DIV>
后面
code
MyDiv.Visible = TRUE; //设置此基础上的cookie值
更新1
这是你如何使用脚本的DIV
<脚本类型=文/ JavaScript的>
$(文件)。就绪(函数(){$('#'<%= MyDiv.ClientID%GT;)负载('popup.html');})
< / SCRIPT>
更新2
我在更新1.犯了一个错误你应该写的jQuery选择像'#<%= MyDiv.ClientID%GT;
,而不是像'#'<%= MyDiv.ClientID%方式>
(注意'引号)
和,你还在你的脚本犯了一个错误。你已经错过了的})在脚本的结尾。
总之,这里的工作方案。 (我试过这么不告诉它不工作: - ))
<脚本类型=文/ JavaScript的>
$(文件)。就绪(函数(){$('#<%= webform.ClientID%GT;')负载('popup.html');})
< / SCRIPT>
< DIV ID =表单=服务器>< / DIV>
希望你能理解这一点。
Is it Possible to show/notshow a div in asp.net depending if cookies are set or not? Note: the div is an html form invoked with javascript in asp.net.
Here the code in asp.net
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">
<script type="text/javascript">
$(document).ready(function () { $('#'<%= webform.ClientID %>).load('popup.html');
</script><div id="webform" runat="Server">
</div>
</asp:Content>
And in code behind:
protected void Page_Load(object sender, EventArgs e)
{ webform.Visible= true;}
Note that the webform is visible when the code is: (nothing is code behind)
<script type="text/javascript">
$(document).ready(function () { $('#webform').load('popup.html'); })
</script>
<div id="webform" >
</div>
</asp:Content>
The goal is to make this visible or not depending if cookie has been set or not. I already tested that the form (in HTML) is setting the cookies(with javascript through webform)
Here's the logic for you to try
Make your DIV a server control by adding
runat="server"
propertyAlso have an
ID
property for your DIV tagset this DIV's visibility from your code behind based on the Cookie values
E.g.
Markup code
<div id="MyDiv" runat="server"></div>
Code behind
MyDiv.Visible = true; // set this based on the cookie value
UPDATE 1
This is how you'd use your DIV in Scripts
<script type="text/javascript">
$(document).ready(function () { $('#'<%= MyDiv.ClientID %>).load('popup.html'); })
</script>
UPDATE 2
I made a mistake in my UPDATE 1. You should write the JQuery selector like '#<%= MyDiv.ClientID %>'
and not like '#'<%= MyDiv.ClientID %>
(Note the ' marks).
And, you also made a mistake in your script. You've missed a }) at the end of the script.
Anyway, here's the working solution. (I tried it so don't tell it's not working :-))
<script type="text/javascript">
$(document).ready(function () { $('#<%= webform.ClientID %>').load('popup.html');} )
</script>
<div id="webform" runat="Server"></div>
Hope you could understand this.
这篇关于在显示条件asp.net一个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!