2013-01-08 29 views
3

試圖從按鈕切換到超鏈接(以前的帖子),但無法讓它工作,所以決定使用鏈接按鈕。從type =「button」切換到asp:LinkBut​​ton

在我的aspx頁面

我使用

<script type ="text/javascript"> 
     function showImg(url) 
     { 
        $("#imagePreview").attr("src", url); 

     } 
</script> 

     <div style="height:50px; margin-top:25px; margin-bottom:25px;"> 
      <img id="imagePreview" alt="" width="30" height ="30"></img> 
     </div> 

然後在我的ascx頁面我使用

<input type="button" onclick='javascript:showImg("<%# FieldValueString %>")' /> 

這工作得很好,當按鈕被點擊的PIC將顯示如下不過,我想改爲鏈接按鈕。

我用盡上http://www.devmanuals.com/tutorials/ms/aspdotnet/linkbutton.html但沒有喜悅的例子,

IV試圖

<asp:LinkButton 
     ID="LinkButton1" 
     runat="server" 
     Text="Preview" 
     Font-Bold="True" 
     ForeColor="Maroon" 

     PostBackUrl='javascript:showImg("<%# FieldValueString %>")' /> 

但是當我按一下按鈕我必須anycode添加到.cs文件沒有任何反應?

請幫

thaks

回答

6

您正在使用不正確的屬性。試試這個:

<asp:LinkButton 
     ID="LinkButton1" 
     runat="server" 
     Text="Preview" 
     Font-Bold="True" 
     ForeColor="Maroon" 
     OnClientClick='javascript:showImg("<%# FieldValueString %>"); return false;' /> 
相關問題