在ClientScript.RegisterClientScriptBlock之后显示/隐藏div CollapsePanel [英] Showing/Hiding div CollapsePanel after ClientScript.RegisterClientScriptBlock
问题描述
此问题是显示/隐藏div 的扩展.
如上所述,我找到了一种解决方法,以防止折叠"面板在加载时闪烁.
As stated, I found a workaround to prevent a Collapse panel from flashing upon load.
我的解决方法是这样:
在标题中:
function showDivs() {
divMenuContent.style.visibility = 'visible';
divMenuContent.style.display='block';
}
</script>
,面板在div中隐藏为:
and panel hidden in div as:
<div id="divMenuContent" style="visibility:hidden; display:none;">
<asp:Panel ID="pnlAddNewContent" runat="server" CssClass="collapsePanel" Width="500px">
</asp:Panel>
</div>
,身体负荷为onLoad ="javascript:showDivs();"
and body load is onLoad="javascript:showDivs();"
问题是,它可以完美地在空白页上运行.但是我想当我做
The thing is, it works perfectly on a blank page. But I think when I do a
ClientScript.RegisterClientScriptBlock(this.GetType(), "", sb.ToString());
它不起作用-因为在面板中没有折叠/显示.上面的代码确实有效.
it doesn't work - as in the panel doesnt collapse/show. The above code does work.
您认为clientScipt与我的JavaScript冲突以显示div吗?我没有在浏览器中收到任何Javascript运行错误.
Do you believe the clientScipt conflicts with my javascript to show div? I don't receive any Javascript run errors within browser.
更多信息:如果clientScript不是回发,则将调用clientScript.我还尝试通过在客户端脚本的末尾添加以下代码来从客户端脚本调用javascript:
More info: The clientScript is called if its not a postback. I have also tried to call the javascript from the clientscript by adding the following code at the end of it:
sb.Append("\n}\nshowDivs();</script>\n");
但是这次我得到以下错误:
But this time I get the following error:
divMenuConent未定义.
divMenuConent is undefined.
有解决方案吗?
推荐答案
对于这种要求,您可以使用 RegisterStartupScript
.
You can use RegisterStartupScript
for this kind Requirement.
这篇关于在ClientScript.RegisterClientScriptBlock之后显示/隐藏div CollapsePanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!