[英]Div is not shown when button click event in asp.net page?
在我的ASP頁面中,我創建了一個按鈕,在該按鈕的單擊事件中,我想顯示我的div標簽部分。實際上,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部分都沒有出現......我不知道這里有什么問題......
請指導我擺脫這個問題......
為什么你不應該在你的asp.net按鈕中使用OnClientClick
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="ShowPopUp(); return false;"> </asp:Button>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.