2012-11-22 42 views
1

在我的ASP頁面中,我創建了一個按鈕,並在該按鈕的單擊事件中,我想顯示我的div標籤部分。實際上,Div部分包含一個文本框和兩個按鈕。當asp.net頁面中的按鈕點擊事件時div不顯示?

這是我的aspx頁面內容:

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> 
<style type="text/css"> 
#popup 
{ 
    display:none; 
    position: fixed; 
    width:250px; 
    height: 150px; 
    top: 50%; 
    left: 50%; 
    margin-left:-155px; 
    margin-top:-110px; 
    border:5px solid red; 
    background-color:#DEDFDE; 
    padding:30px; 
    z-index:102; 
    font-family:Verdana; 
    font-size:10pt; 
    -webkit-border-radius:20px; 
    -moz-border-radius:20px; 
    font-weight:bold; 
} 
#content 
{ 
    height:auto; 
    width:250px; 
    margin:60px auto; 
} 
#popupclose 
{ 
    margin:35px 0 0 80px; 
    width:50px; 

} 
</style> 
</asp:Content> 

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> 

<script type="text/javascript" language="javascript"> 
    function ShowPopUp() 
    { 
     $('#popup').show("slow"); 
    } 

    function hidePopUp() 
    { 
     $('#popup').hide("slow"); 
    } 
</script> 


    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Test"> 
    </asp:Button> 

    <div id="popup"> 
     <div id="content"> 
      <input type="text"/><input type="button" value="Browse"/> 
      <input id="popupclose" type="button" value="Close" onclick="hidePopUp();/> 
     </div> 
    </div> 

</asp:Content> 

和我的C#代碼如下:

protected void Test(object sender,EventArgs e) 
     { 
     ClientScript.RegisterStartupScript(GetType(), "popup", "ShowPopUp()", true); 
     } 

但每當我按一下按鈕,在div部分沒有顯示出來......我不知道什麼是這裏的問題...

請指引我走出這個問題...

+0

是您的測試()方法調用? – Talha

+0

是的...這是我的C#函數 – Saravanan

回答

4

爲什麼你不應該使用OnClientClick在asp.net按鈕,這樣

<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="ShowPopUp(); return false;"> </asp:Button> 
+1

該按鈕仍然不會做回發,一旦頁面重新加載,使現在可見的div再次隱藏嗎? – rikitikitik

+1

@rikitikitik你不需要onClick方法,並防止回發使用返回false;隨着我更新......無論如何感謝 – Talha

+0

對不起,它無法正常工作... – Saravanan