我知道有一個類似的問題,但該答案並沒有解決我的問題。Javascript Alert破壞我的asp.NET Web應用程序的佈局
這是我的應用程序的外觀正常:
,這是它的外觀JavaScript警告後(菜單項寬度被擰緊,左邊的紫色欄增加了一個額外的部分它在上面):
這是我使用打電話報警代碼:
private void Alert(string msg)
{
Response.Write("<script language = 'javascript'>window.alert('" + msg + "')</script>");
}
有沒有人有過這個問題,即使是默認的asp.NET設計,我也有類似的東西。我怎樣才能解決這個問題?順便說一句,我使用的是IE 7,在Firefox上可以。
更新:
修正了紫色條問題,除去保證金。仍然找出菜單寬度問題。
這是我的CSS:
#menu
{
position: absolute;
left: 78%;
top: 108px;
width: 170px !important;
}
div.menu
{
padding: 4px 0px 4px 8px;
}
div.menu ul
{
list-style: none;
margin: 0px;
padding: 0px;
width: auto;
}
div.menu ul li a, div.menu ul li a:visited
{
background-color: #FFF; /*680840*/
border: 1px #4e667d solid;
height: 20px;
width: 140px;
color: #000; /*FFF*/
display: block;
line-height: 1.35em;
padding: 4px 20px;
text-decoration: none;
white-space: nowrap;
}
div.menu ul li a:hover
{
background-color: #680840;
color: #FFF;
text-decoration: none;
}
.selectedMenu
{
background-color: #680840;
color: #FFF;
text-decoration: none;
}
div.menu ul li a:active
{
background-color: #680840;
color: #cfdbe6;
text-decoration: none;
}
更新對於@Sassyboy:
前端:
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:HiddenField Value="" ID="errorMessageHidden" runat="server"/>
<script type="text/javascript">
var alertMsg = document.getElementById('errorMessageHidden');
if (alertMsg != null) alert(alertMsg);
</script>
和C#我補充一點:
errorMessageHidden.Value = "Failed to Select - Test";
看起來像頭空格(或別的東西)是影響整個頁面。你可以包括更多的上下文,也許在JS小提琴或鏈接到演示? – 2011-08-17 12:57:56
具有高於``或DTD聲明的元素給出了未定義的行爲,這就是你所得到的。如何不將元素插入到Response流的開頭。 – 2011-08-17 12:59:04
@馬特 - Sry基因沒有鏈接的網頁,而不能使用JS小提琴,因爲頁本身是好的,當警報方法是從我的C#文件稱它是一種產生問題。 – 2011-08-17 13:02:01