我知道這樣的問題已經在SO上提過了,我也經歷了其中的大部分,但沒有人滿足我,所以我發佈了我的一個。附件是我的代碼。實際上,我正在從數據庫的代碼構建一個jquery庫。看到代碼:方法在asp.net的頁面加載期間發射兩次
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DisplayHotProducts();
}
}
private void DisplayHotProducts()
{
var dt = ProductData.GetAllHotProducsts();
if (dt != null && dt.Rows.Count > 0)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(" <div id='spotlight_products' class='widget_box center_box'>");
sb.AppendLine("<div class='wintitle'>");
sb.AppendLine(" <div class='inner_wintitle'>");
sb.AppendLine(" Hot Products</div></div>");
sb.AppendLine("<div class='winbody'>");
sb.AppendLine("<div class='mall_focus' id='mall_focus'>");
sb.AppendLine("<a id='bp_carousel_prev'>prev</a>");
sb.AppendLine("<a id='bp_carousel_next'>next</a>");
sb.AppendLine("<div id='bp_carousel'>");
sb.AppendLine(" <div class='carousel_list'>");
for (int i = 0; i < dt.Rows.Count; i=i+5)
{
sb.AppendLine(" <div class='product_list'>");
sb.AppendLine("<div class='bestproduct_wrapper'> <div class='bestproduct'>");
sb.AppendLine(" <div class='icon_best'></div>");
sb.AppendLine("<ul>");
sb.AppendLine(" <li class='best_Img'><span></span><a href='#' target='_blank'> ");
sb.AppendLine(string.Format(" <img src='{0}' width='200' height='200' /></a></li>", dt.Rows[i]["ImagePath"]));
sb.AppendLine("</ul>");
sb.AppendLine(" <p class='product_name'>");
sb.AppendLine(string.Format("<a href='Products/{0}' target='_blank'>{1}</a></p>", dt.Rows[i]["Id"], dt.Rows[i]["Name"]));
sb.AppendLine("</div></div>");
for (int j = i+1; j <= 4; j++)
{
sb.AppendLine("<div class='product_item'>");
sb.AppendLine("<ul><li class='product_Img'>");
sb.AppendLine(string.Format("<a href='Products/{0}'><img src='{1}' width='70' height='70'/></a>", dt.Rows[j]["Id"], dt.Rows[j]["ImagePath"]));
sb.AppendLine("</li></ul>");
sb.AppendLine(string.Format("<p class='product_name'><a href='Products/{0}'>{1}</a></p>", dt.Rows[j]["Id"], dt.Rows[j]["Name"]));
sb.AppendLine("</div>");
}
}
sb.AppendLine(@" </div></div></div></div></div>");
ltlHotProducts.Text = sb.ToString();
}
}
}
我後面的代碼只有上面的代碼和頁面負載射擊兩次。
此外,這是一個用戶控件的代碼背後,放置在一個頁面,我有3個更類似的控制執行相似的功能,即從代碼後面構建jquery幻燈片。但是上面的兩個用戶控件對img標籤有一些問題,因爲其中一些缺少圖像。此外,用戶控制的頁面也有一個母版頁。現在請給我解決方案。
所以層次結構是這樣的:
Master Page (master) -> Content Page (aspx) -> Has->3 UserControls (ascx)
這是什麼問題? – Steven 2011-12-18 18:43:30
什麼是aspx頁面中爲AutoEventWireup設置的值? – 2011-12-18 18:54:58
其默認爲真 – 2011-12-18 18:57:12