保持 div 在回发时显示
我有一个网络用户控件和一个div在里面;一些 jQuery 会切换 div 的可见性。还有一个 asp:button 可以启动一些服务器端代码。
我需要在回发后恢复 div 的可见性。
我正在关注 中发布的更新解决方案这篇文章的解决方案。这是我的代码:
在 ascx 的顶部,在寄存器之后:
<script>
function SetHiddenValue()
{
var campo = document.getElementById("<% =hidHiddenField.ClientID %>");
if(campo.Value == "NO")
{
document.getElementById("<% =hidHiddenField.ClientID %>").Value = "SI";
}
else
{
document.getElementById("<% =hidHiddenField.ClientID %>").Value = "NO";
}
}
</script>
div 定义:
<div id="divContenidoMetricas" style='<%= DefinirVisibilidad() %>'>
在同一个 Web 用户控件中:
<asp:ImageButton runat="server" ImageUrl="~/Themes/Images/buscar.PNG" OnClick="btnFiltrar_Click"
ID="btnFiltrar" OnClientClick="SetHiddenValue()" />
在 ascx.cs 中:
protected string DefinirVisibilidad()
{
return this.hidHiddenField.Value == "SI" ? "display:block" : "display:none";
}
它只是不起作用。 hidHiddenField.Value 始终以相同的值到达服务器代码 (DefinirVisibilidad())。
非常感谢您的帮助...我的客户端代码知识有点被 ASP.NET 破坏了,所以我陷入了困境。
已解决
我将“值”替换为“值”,这解决了问题。它正在工作!
I have a web user control and a div inside it; some jQuery toggles div's visibility. There is also a asp:button that launches some server side code.
I need to restore div's visibility after postback.
I'm following the updated solution posted in the this post's solution. Here is my code:
At the top of the ascx, after the Registers:
<script>
function SetHiddenValue()
{
var campo = document.getElementById("<% =hidHiddenField.ClientID %>");
if(campo.Value == "NO")
{
document.getElementById("<% =hidHiddenField.ClientID %>").Value = "SI";
}
else
{
document.getElementById("<% =hidHiddenField.ClientID %>").Value = "NO";
}
}
</script>
The div definition:
<div id="divContenidoMetricas" style='<%= DefinirVisibilidad() %>'>
In that same web user control:
<asp:ImageButton runat="server" ImageUrl="~/Themes/Images/buscar.PNG" OnClick="btnFiltrar_Click"
ID="btnFiltrar" OnClientClick="SetHiddenValue()" />
In the ascx.cs:
protected string DefinirVisibilidad()
{
return this.hidHiddenField.Value == "SI" ? "display:block" : "display:none";
}
It is just not working. hidHiddenField.Value arrives to the server code (DefinirVisibilidad()) with the same value all the times.
Thanks so much in advance for your help... my client side code knowledge is kind of damaged by ASP.NET so I'm stuck.
SOLVED
I replaced 'Value' with 'value' and that solved the problem. It's working!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请尝试一下:
编辑:将“Value”替换为“value”。
Try this, please:
EDIT: Replaced "Value" with "value".
使用 jQuery 将其设置为文档就绪怎么样?
而不是直接使用 <% %> 设置样式;块。
How about using jQuery to set it on document ready?
Instead of setting the style directly using <% %> blocks.
值必须是小写,因此替换后有效:
Value has to be lowercase, so it worked after replacing: