2010-01-25 60 views
1

我有一個鏈接按鈕,裏面有圖像和標籤。 回發後,圖像和標籤不可見。asp.net鏈接按鈕圖像回傳後不可見

< asp:LinkButton ID="AddNewRunLinkButton" runat="server" CssClass="Navigationlocalnav" 
OnClick="AddNewRunLinkButton_Click" > 
&nbsp; 
    < img id="Img1" src="../../Images/add_newIcon.gif" runat="server" alt="Add New Run" /> 
    < asp:Label ID="addText" Text=" Add New Run" runat="server"></asp:Label> 
< /asp:LinkButton> 

此鏈接按鈕用於導入/導出數據。我點擊這個鏈接按鈕(AddNewRunLinkBut​​ton)添加了一個屬性來顯示一個使用javascript - SetInterval函數的進度條。 如果我刪除這個屬性,圖像和標籤就會顯示出來,否則只會顯示鏈接按鈕。

AddNewRunLinkButton.attributes.add("onclick","javascript:DisplayProgress()"); 

function DisplayProgress() 
{ 
    timeid = setInterval("addBlock",100) 
} 

function Addblock() 
{ 
// Display a progress bar as follows - Increase the width of a div tag at this interval 
} 

任何幫助?

+0

一些代碼示例很好看,如果你想得到一些幫助。 – 2010-01-25 10:13:01

+0

看到上面的代碼片段...在該圖像和標籤沒有得到顯示後回發 – 2010-01-25 10:15:17

+0

該代碼甚至不會顯示圖像的第一個地方。你真的需要給我們更多的東西繼續下去。 – 2010-01-25 10:15:42

回答

0

由於你的代碼示例沒有太多的繼續我發佈了一些東西,我認爲可能是你想要做的。

標記和Javascript:

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"> 
    <title>Untitled Page</title> 
    <script language="javascript" type="text/javascript"> 
    var timeID = null; 
    var width = 0; 

    function DisplayProgress() { 
     timeID = setInterval('AddBlock();', 100); 
    } 

    function AddBlock() { 
     var p = document.getElementById("progressDiv"); 
     if (width < 1000) { 
     width += 100; 
     p.style.width = width + "px"; 
     } 
     else 
     timeID = clearInterval(timeID); 
     } 
    </script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:LinkButton runat="server" ID="lbAddNewRun" OnClick="lbAddNewRun_Click"> 
     <img src="--url to an image--" alt="Add New Run" /> 
     Add New Run 
     </asp:LinkButton> 
    </div> 
    <div id="progressDiv" style="background-color: Green; width: 0px; height: 20px;"></div> 
    </form> 
</body> 
</html> 

代碼隱藏:

protected void Page_Load(object sender, EventArgs e) 
{ 
    lbAddNewRun.Attributes.Add("OnClick", "javascript:DisplayProgress();"); 
} 

protected void lbAddNewRun_Click(object sender, EventArgs e) 
{ 
    // Export/Import code. 
} 

這不 「隱藏」 的形象,對我來說ATLEAST。

備註:
而不是在添加OnClick事件的代碼隱藏,你可以直接在標記添加它,因爲它不是動態創建的:

 <asp:LinkButton runat="server" ID="lbAddNewRun" OnClick="lbAddNewRun_Click" OnClientClick="DisplayProgress();"> 
     <img src="--url to an image--" alt="Add New Run" /> 
     Add New Run 
     </asp:LinkButton> 
+0

嗨Sani,代碼或多或少相似...除了以下區別... 1.我不使用clearInterval,因爲我想開始從0開始,如果寬度達到1000. 2.我有一個asp:標籤控制後的圖像控制...其中包含文本 - 「添加新的運行」當我看着視圖源...我能看到一個錨標籤而不是鏈接按鈕...和nno圖像和標籤控件:(。 計時器停止,因爲回發發生在我的情況...不使用clearInterval..will達到會導致問題? – 2010-01-25 11:31:06

+0

你可以發佈AddBlock javascript function? – 2010-01-25 11:43:57

+0

function DisplayProgress(progressDiv) {var progressBar = document.getElementById(「ProgressBar」); timerId = setInterval(「addBlock('」+ progressDiv +「')」,100);} function addBlock(progressDiv){var進度=的document.getElementById(progressDiv); progress.style.align =「left」; var width = parseInt(progress.style.width); if(width <500){progress.style.width = width + 10 +「px」; } else {progress.style.width =「0px」; } progress.style.backgroundColor ='blue'; progress.style.cssFloat ='left'; progress.style。styleFloat ='left'; } – 2010-01-25 11:52:39

0

我會用異步調用show進度條,而不是你在這裏做什麼。有時候,當您連接客戶端和服務器端事件時,頁面呈現不能按預期工作。在這種情況下,您正在使用一個帶有SetInterval的Javascript計時器,我相信這會導致標籤消失。