如何在点击按钮后回发后显示div?

时间:2012-03-21 11:00:51

标签: c# javascript jquery asp.net postback

这里我有一个div,我在鼠标悬停在母版页中显示它,鼠标悬停后,三个href链接将出现在该div中。点击该href链接后,它将遍历到另一个页面,回发发生, div被隐藏在母版页中。我需要在点击之后显示div。我已经使用了updatepanel并尝试了但仍然没有工作。我的代码是

// Div part

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="Update" runat="server">
<ContentTemplate>
<div runat="server" class="divSUBMenu" id="describe" style="width: 700px; height: 20px;
 font: Arial, Helvetica, sans-serif;" onclick="show(0)">
</div>
</ContentTemplate>
</asp:UpdatePanel>

// Onhover part

 <a href="#" onmouseover="showit(0)">
 <img src="Images/Analyze_over.jpg" name="image1" width="84" height="22" border="0"
 id="image1" alt="" /></a>

//用于mousehover的Javascript(正常工作)

var submenu = new Array();
    submenu[0] = '&nbsp;<font style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;"><a style="color: #FFFFFF; text-decoration: none;" href="ATrendAnalysis.aspx">Trend Analysis</a> &nbsp;&nbsp; <a style="color: #FFFFFF; text-decoration: none;" href="AEventPerformance.aspx">Event Performance</a> &nbsp;&nbsp; <a style="color: #FFFFFF; text-decoration: none;" href="ACannibalization.aspx">Cannibalization</a> &nbsp;&nbsp; <a style="color: #FFFFFF; text-decoration: none;" href="AHaloEffect.aspx">Halo Effect</a> &nbsp;&nbsp; <a style="color: #FFFFFF; text-decoration: none;" href="AVolumeDecomposition.aspx">Volume Decomposition</a></font></span>';
        var delay_hide = 500;
        var menuobj = document.getElementById ? document.getElementById("describe") : document.all ? document.all.describe : document.layers ? document.dep1.document.dep2 : "";

        function showit(which) {
                clear_delayhide();
            document.getElementById("describe").style.visibility = 'visible';
            thecontent = (which == -1) ? "" : submenu[which];
            if (document.getElementById || document.all) {
                menuobj.innerHTML = thecontent;
            }
            else if (document.layers) {
                menuobj.document.write(thecontent);
                menuobj.document.close();
            }
        }

最后,在onclick期间,下面的部分无效,但此警报正在运行

function show(which) {
alert("test");
document.getElementById("describe").style.visibility = 'visible';
}

有什么建议吗?

编辑: 这是点击

的href
<a style="color: #FFFFFF; text-decoration: none;" href="ATrendAnalysis.aspx">Trend Analysis</a>

2 个答案:

答案 0 :(得分:2)

您必须使用ClientScriptManager

http://msdn.microsoft.com/en-us/library/3hc29e2a.aspx

示例:

void Page_Load(object sender, EventArgs e)
{
    if(checkDisplayCount.Checked)
    {
        String scriptText = "";
        scriptText += "function DisplayCharCount(){";
        scriptText += "   spanCounter.innerText = " + 
            " document.forms[0].TextBox1.value.length";
        scriptText += "}";
        ClientScriptManager.RegisterClientScriptBlock(this.GetType(), 
           "CounterScript", scriptText, true);
        TextBox1.Attributes.Add("onkeyup", "DisplayCharCount()");
        LiteralControl spanLiteral = new 
            LiteralControl("<span id=\"spanCounter\"></span>");
        PlaceHolder1.Controls.Add(spanLiteral);
    }
}

答案 1 :(得分:0)

由于div设置为runat=server,您可以在服务器端对此进行控制 - 最初设置describe.IsVisible = false,然后将其更改为describe.IsVisible = true点击后。< / p>

如果无论出于何种原因,必须在客户端上完成,由于依赖其他脚本或其他东西,那么请确保您使用正确的标识符来查找控件 - 它可能,取决于您使用的ASP.NET版本,控件的前缀为ctl00_x。实际上,即使在较新版本的ASP.NET(在.NET 3.5之上),我认为UpdatePanel 可能使用前缀显式改变其元素的标识符,以便跟踪它包含什么,不要引用我的话。检查页面上呈现的标记输出以检查它。