在我的 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>
关于c# - 在 asp.net 页面中单击按钮事件时不显示 Div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13507461/