2012-03-21 68 views
1

在這裏我有一個div,在鼠標懸停在主頁面和鼠標懸停後,三個href鏈接將出現在該div中。在單擊該鏈接後,它正在遍歷另一個頁面,發生回發, DIV是越來越隱藏在主page.I需要證明點擊also.I已經使用的UpdatePanel後的div和嘗試過,但它仍然不是working.here是我的代碼如何在點擊按鈕回發後顯示div?

//股利部分

<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選項部分

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

// JavaScript進行mousehover(做工精細)

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> 
+0

嘗試'document.getElementById(「describe」)。setAttribute(「style」,「display:block;」);'它可能工作。 – Murtaza 2012-03-21 11:06:31

+0

我已嘗試也仍然沒有工作 – bala3569 2012-03-21 11:09:26

回答

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); 
    } 
} 
+0

這一個\ – bala3569 2012-03-21 11:09:40

+0

No..Let我給你一個例子 – 2012-03-21 11:11:58

+0

投票嗎?或者接受它是否有效 – 2012-03-21 11:15:05

0

由於div設置爲runat=server,您可以在服務器端進行控制 - 最初設置describe.IsVisible = false,並將其更改爲describe.IsVisible = true單擊後。

如果因任何原因,這必須在客戶端上完成,由於對其他腳本或依賴的東西,然後通過使用正確的標識符確保你正在尋找的控制 - 它可能是,根據在您使用的ASP.NET版本上,該控件的前綴爲ctl00_x。事實上,即使在較新版本的ASP.NET(.NET 3.5以上版本)中,我認爲可能會使用前綴明確地更改其元素的標識符,以便跟蹤它包含的內容,請勿引用我儘管如此。檢查頁面上呈現的標記輸出以檢查這一點。

相關問題