2012-03-15 31 views
0

基本上,我们对MasterPage中的.Visible = false存在的通知消息框有个“幻觉”。当谈到时间在框中显示的消息,我们运行,看起来像这样的方法:使用JavaScript更改页面状态,旧状态在回发中调用

public static void DisplayNotificationMessage(MasterPage master, string message) 
{ 
    if (Master.FindControl("divmsgpanel") != null) 
    { 
     master.FindControl("divmsgpanel").Visible = true; 
    } 

    if (master.FindControl("divdimmer") != null) 
    { 
     master.FindControl("divdimmer").Visible = true; 
    } 

    TextBox thetxtbox = (TextBox)master.FindControl("txtboxmsgcontents"); 

    if (thetxtbox != null) 
    { 
     thetxtbox.Text = message; 
    } 

}

基本上是通过我们的设计师真棒CSS巫术,我们最终似乎是一个浮动消息框,因为页面的其余部分显示为灰色。这个消息框有一个“关闭”按钮来关闭“弹出”并恢复调光器,使该站点返回到“正常”视觉状态。我们在母版的JavaScript实现这一点:

function HideMessage() { 
     document.getElementById("<%# divmsgpanel.ClientID %>").style.display = 'none'; 
     document.getElementById("<%# divdimmer.ClientID %>").style.display = 'none'; 
     return false; 
    } 

和按钮在.aspx页的声明称这HideMessage()函数的OnClientClick:

<asp:Button ID="btnmsgcloser" runat="server" Text="Close" style="margin: 5px;" 
    OnClientClick="return HideMessage()" /> 

问题:

所有将来的回发都会导致MasterPage从HideMessage()之前的方式“记住”这些div的状态JavaScri pt被执行了。换句话说,在DisplayNotificationMessage()方法初始调用后的每次回发都会导致页面返回到divmsgpanel.Visible = true和divdimmer.Visible = true,从而创建一个无限烦人的消息框,在每次回发时都会弹出错误消息框。

问题:

因为我们想让关闭功能保持客户端JavaScript,我们怎么能“通知”页面停止恢复旧态上回发,只是这两个div?

回答

2

你可以尝试在Master_Page Load事件中将它们设置为Visible = false吗?它应该隐藏它们,并重新显示它们只是当你打电话DisplayNotificationMessage

+0

Omg,谢谢!这工作。哇,现在很痛苦。非常感谢。 – CptSupermrkt 2012-03-15 08:00:01