我有一個.NET 4.5 .ascx控件在客戶端頁面(服務器端,當然)呈現HTML和jQuery腳本。我目前正在本地化本控件所屬的網站(尚未獲得此控件),並且在更改IE9中的語言時遇到了一些奇怪的問題。jQuery與.NET 4.5控件的本地化問題
當瀏覽器語言設置爲英文時,該控件看起來很好,並且工作正常。但是,當它改變爲任何其他語言時,控件不會響應任何jQuery事件。它呈現應有的樣子,一切看起來都不錯......它只是不會響應任何鼠標懸停/跳出或點擊事件。
如果我將瀏覽器語言設置回英文,一切正常。有什麼我失蹤?
這裏是控制代碼(針對的.ascx頁面只是一個asp.net文本)和jQuery腳本,它與它一起呈現:
using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Configuration;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Text;
using MyCode.DBS.DataEntities;
using MyCode.DBS.BusinessCore;
using MyCode.DBS.Utilities;
namespace MyCode.DBS.WebCore.Controls
{
public partial class MetroTiles : System.Web.UI.UserControl
{
// Global Crypto Key
private string CRYPTO_KEY = Convert.ToString(HttpContext.Current.Application["CRYPTO_KEY"]);
// Get Framework Image Location
private string IMAGE_LOC = Convert.ToString(WebConfigurationManager.AppSettings["HDBSFrameworkImages"]);
// Ratio of normal slide height (or width for horz) to tile height.
private const decimal SLIDE_HW_RATIO = .3m;
// Ratio of extended slide height (or width for horz) to normal slide height.
private const decimal SLIDE_HW_EXT_RATIO = .5m;
// Slide icon cell reservation size
private const int SLIDE_ICON_CELL_SZ = 40;
// TESTED 09/27/2013 - PASSED! - B. Nichols
protected void Page_Load(object sender, EventArgs e)
{
MetroTileGroup group = null;
StringBuilder sb_HTML = null;
int grpCellHeight = 0;
int grpCellWidth = 0;
int grpMarginTop = 0;
int grpMarginLeft = 0;
int tileCellHeight = 0;
int tileCellWidth = 0;
int tileHeight = 0;
int tileWidth = 0;
string tileCellSpan = string.Empty;
string tileClass = string.Empty;
string tileID = string.Empty;
string tileCursorStyle = string.Empty;
string tileBkGrndStyle = string.Empty;
string tileSlideBkGrnd = string.Empty;
bool tileActive = false;
int tileSlideHeight = 0;
int tileSlideWidth = 0;
int tileSlideExt = 0;
string tileSlideTable = string.Empty;
string tileSlideMargin = string.Empty;
int currentRow = 0;
int prevRow = 0;
try
{
// Check existance of CRYPTO_KEY
if (string.IsNullOrWhiteSpace(CRYPTO_KEY))
throw new NullReferenceException("Application Encryption Key Not Found");
// Get Tile Group & Associated Tiles
group = Support.GetMetroGroup(this.TileGroupID, WebConfigurationManager.ConnectionStrings[this.ConnectionStringName], CRYPTO_KEY);
if (group != null)
{
// Set Tile Cell Dimentions (Group Table)
grpCellHeight = group.MetroStdTileHeight + (group.MetroBorderSize * 2) + (group.MetroMarginSize * 2);
grpCellWidth = group.MetroStdTileWidth + (group.MetroBorderSize * 2) + (group.MetroMarginSize * 2);
// Set TOP and LEFT Margins for Tile Group (Center)
grpMarginTop = (grpCellHeight * group.MetroGroupRows)/2;
grpMarginLeft = (grpCellWidth * group.MetroGroupColumns)/2;
// Initiate Group (Table) Layout
// Set Group Header
sb_HTML = new StringBuilder();
sb_HTML.AppendFormat("<table style=\"position: relative; top: 40%; left: 50%; margin: -{0}px 0 0 -{1}px; border-collapse: collapse\">\n",
grpMarginTop.ToString(), grpMarginLeft.ToString());
sb_HTML.AppendLine("\t<tr>");
sb_HTML.AppendFormat("\t\t<td style=\"font: normal 1.4em 'Segoe UI Light'; color: #FFFFFF; padding: 5px\" colspan=\"{0}\">\n",
group.MetroGroupColumns.ToString());
sb_HTML.AppendFormat("\t\t\t{0}\n", Server.HtmlEncode(group.MetroGroupHeader));
sb_HTML.AppendLine("\t\t</td>");
sb_HTML.AppendLine("\t</tr>");
// Set Individual Tiles
foreach (MetroTileItem tile in group.MetroGroupTiles)
{
// Set current row counter
currentRow = tile.TileItemRow;
// Check if table row tags need closed or opened (
if (!currentRow.Equals(prevRow))
{
// Close previous row tag (If not first row)
if (!prevRow.Equals(0))
sb_HTML.AppendLine("\t</tr>");
sb_HTML.AppendLine("\t<tr>");
}
// Get tile size by tile type
switch (tile.TileItemType)
{
case MetroTileType.Square:
tileID = string.Format("sTile_{0}", tile.TileItemID.ToString());
tileCellHeight = grpCellHeight;
tileCellWidth = grpCellWidth;
tileHeight = group.MetroStdTileHeight;
tileWidth = group.MetroStdTileWidth;
tileCellSpan = string.Empty;
break;
case MetroTileType.Vertical:
tileID = string.Format("vTile_{0}", tile.TileItemID.ToString());
tileCellHeight = grpCellHeight * 2;
tileCellWidth = grpCellWidth;
tileHeight = (group.MetroStdTileHeight * 2) + (group.MetroMarginSize * 2) + (group.MetroBorderSize * 4);
tileWidth = group.MetroStdTileWidth;
tileCellSpan = "rowspan=\"2\"";
break;
case MetroTileType.Horizontal:
tileID = string.Format("hTile_{0}", tile.TileItemID.ToString());
tileCellHeight = grpCellHeight;
tileCellWidth = grpCellWidth * 2;
tileHeight = group.MetroStdTileHeight;
tileWidth = (group.MetroStdTileWidth * 2) + (group.MetroMarginSize * 2) + (group.MetroBorderSize * 4);
tileCellSpan = "colspan=\"2\"";
break;
}
// Get tile hover effect
switch (tile.TileItemEffect)
{
case MetroTileHoverEffect.None:
break;
case MetroTileHoverEffect.Slide:
tileClass = "slideTile";
tileSlideBkGrnd = tile.TileItemForeground;
break;
case MetroTileHoverEffect.VerticalAxisFlip:
tileClass = "vertFlipTile";
break;
case MetroTileHoverEffect.HorizontalAxisFlip:
tileClass = "horzFlipTile";
break;
}
// Determine if tile is hyperlinked.
if (!string.IsNullOrWhiteSpace(tile.TileItemURL))
{
tileClass += " activeTile";
tileCursorStyle = "cursor: pointer;";
tileActive = true;
}
else
{
tileCursorStyle = string.Empty;
tileActive = false;
}
// Determine if blank (empty) tile
if ((!tileActive) && (string.IsNullOrWhiteSpace(tile.TileItemLabel)) && (string.IsNullOrWhiteSpace(tile.TileItemIcon)))
tileClass = "blankTile";
// Determine tile background
if (tile.TileItemBackground.StartsWith("#"))
tileBkGrndStyle = string.Format("background-color: {0};", tile.TileItemBackground);
else
tileBkGrndStyle = string.Format("background: url('{0}') center no-repeat;", tile.TileItemBackground);
// Initialize Row Cell
sb_HTML.AppendFormat("\t\t<td style=\"width: {0}px; height: {1}px\" {2}>\n", tileCellWidth.ToString(), tileCellHeight.ToString(), tileCellSpan);
// Start Cell Tile
sb_HTML.AppendFormat("\t\t\t<div class=\"{0}\" id=\"{1}\" style=\"{2} width: {3}px; height: {4}px; position: relative; " +
"margin: {5}px; border: {6}px solid {7}; {8}\">\n", tileClass, tileID, tileBkGrndStyle, tileWidth.ToString(),
tileHeight.ToString(), group.MetroMarginSize.ToString(), group.MetroBorderSize.ToString(), group.MetroBorderColor, tileCursorStyle);
// Add tile effects if not a blank tile
if (!tileClass.Equals("blankTile"))
{
// ** SLIDE TILES **
if (tile.TileItemEffect.Equals(MetroTileHoverEffect.Slide))
{
// Find slide margin by tile type and slide size;
switch (tile.TileItemType)
{
case MetroTileType.Square:
case MetroTileType.Vertical:
tileSlideHeight = (int)Math.Round(tileHeight * SLIDE_HW_RATIO);
tileSlideWidth = tileWidth;
tileSlideExt = (int)Math.Round((tileSlideHeight * SLIDE_HW_EXT_RATIO) + tileSlideHeight);
tileSlideMargin = "bottom: 0px;";
tileSlideTable = string.Format("\t\t\t\t\t<table style=\"width: {0}px; height: {1}px; border-collapse: collapse\">\n" +
"\t\t\t\t\t\t<tr>\n" +
"\t\t\t\t\t\t\t<td style=\"width: {2}px; height: {3}px; font: normal 0.95em 'Segoe UI Semibold'; line-height: 90%; color: #FFFFFF; text-align: left; vertical-align: top; padding: 5px\">\n" +
"\t\t\t\t\t\t\t\t{4}\n" +
"\t\t\t\t\t\t\t</td>\n" +
"\t\t\t\t\t\t\t<td style=\"width: auto; height: {5}px; text-align: right; vertical-align: top; padding-right: 5px; padding-top: 5px\">\n" +
"\t\t\t\t\t\t\t\t<img style=\"border: none\" src=\"{6}/up_arrow_cir.png\" alt=\"Click to Enter\"/>\n" +
"\t\t\t\t\t\t\t</td>\n" +
"\t\t\t\t\t\t</tr>\n" +
"\t\t\t\t\t</table>", tileSlideWidth.ToString(), tileSlideHeight.ToString(), Convert.ToString(tileSlideWidth - SLIDE_ICON_CELL_SZ),
tileSlideHeight.ToString(), Server.HtmlEncode(tile.TileItemLabel).Replace("[NL]", "<br />"), tileSlideHeight, IMAGE_LOC);
break;
case MetroTileType.Horizontal:
tileSlideHeight = tileHeight;
tileSlideWidth = (int)Math.Round(tileWidth * SLIDE_HW_RATIO);
tileSlideExt = (int)Math.Round((tileSlideWidth * SLIDE_HW_EXT_RATIO) + tileSlideWidth);
tileSlideMargin = "left: 0px;";
tileSlideTable = string.Format("\t\t\t\t\t<table style=\"width: {0}px; height: {1}px; border-collapse: collapse; float: right\">\n" +
"\t\t\t\t\t\t<tr>\n" +
"\t\t\t\t\t\t\t<td style=\"width: {2}px; height: {3}px; font: normal 0.95em 'Segoe UI Semibold'; line-height: 90%; color: #FFFFFF; text-align: left; vertical-align: top; padding: 5px\">\n" +
"\t\t\t\t\t\t\t\t{4}\n" +
"\t\t\t\t\t\t\t</td>\n" +
"\t\t\t\t\t\t</tr>\n" +
"\t\t\t\t\t\t<tr>\n" +
"\t\t\t\t\t\t\t<td style=\"width: {5}px; height: auto; text-align: right; vertical-align: bottom; padding-right: 5px; padding-bottom: 5px\">\n" +
"\t\t\t\t\t\t\t\t<img style=\"border: none\" src=\"{6}/right_arrow_cir.png\" alt=\"Click to Enter\"/>\n" +
"\t\t\t\t\t\t\t</td>\n" +
"\t\t\t\t\t\t</tr>\n" +
"\t\t\t\t\t</table>", tileSlideWidth.ToString(), tileSlideHeight.ToString(), tileSlideWidth.ToString(), Convert.ToString(tileSlideHeight - SLIDE_ICON_CELL_SZ),
Server.HtmlEncode(tile.TileItemLabel).Replace("[NL]", "<br />"), tileSlideWidth, IMAGE_LOC);
break;
}
// Initialize slide container
sb_HTML.AppendFormat("\t\t\t\t<div style=\"background-color: {0}; width: {1}px; height: {2}px; position: absolute; z-index: 5; " +
"opacity: 0.7; overflow: hidden; {3}\">\n", tile.TileItemForeground, tileSlideWidth.ToString(),
tileSlideHeight.ToString(), tileSlideMargin);
// Insert pre-composed table
sb_HTML.AppendLine(tileSlideTable);
// Close slide container
sb_HTML.AppendLine("\t\t\t\t</div>");
// Insert hidden anchor if tile is active
if (tileActive)
sb_HTML.AppendFormat("\t\t\t\t<a href=\"{0}\" style=\"display: none\"></a>\n", tile.TileItemURL);
}
// ** OTHER TILE EFFECTS ADDED HERE **
}
// End Cell Tile
sb_HTML.AppendLine("\t\t\t</div>");
// End Row Cell
sb_HTML.AppendLine("\t\t</td>");
// Set previous row counter
prevRow = currentRow;
}
// Close final row and group table (if tiles exist)
if (group.MetroGroupTiles.Count > 0)
sb_HTML.AppendLine("\t</tr>");
sb_HTML.AppendLine("</table>");
sb_HTML.AppendLine();
// Get generated JQuery script for tile group
sb_HTML.AppendLine(CreateTileGroupScript(group));
// Release generated tile group to page content
this.litTileGrp.Text = sb_HTML.ToString();
}
else
throw new DataException(string.Format("Specified Tile Group '{0}' Does Not Exist.", this.TileGroupID.ToString()));
}
catch (Exception ex)
{
throw;
}
}
// TESTED 09/27/2013 - PASSED! - B. Nichols
private string CreateTileGroupScript(MetroTileGroup group)
{
StringBuilder sb_Script = null;
try
{
// The following string is created and formatted in such a way
// to maintain readability while IN THIS CODE!.
// Start Scripting Section
sb_Script = new StringBuilder("<script type=\"text/javascript\">");
sb_Script.AppendLine();
sb_Script.AppendLine();
// SlideTile - MouseEnter event function
sb_Script.AppendLine(" $(\"div.slideTile\").mouseenter(function() {");
sb_Script.AppendLine();
sb_Script.AppendFormat(" var SLIDE_HW_RATIO = {0};\n", SLIDE_HW_RATIO.ToString());
sb_Script.AppendFormat(" var SLIDE_HW_EXT_RATIO = {0};\n", SLIDE_HW_EXT_RATIO.ToString());
sb_Script.AppendLine();
sb_Script.AppendLine(" if (this != null) {");
sb_Script.AppendLine();
sb_Script.AppendLine(" // Get tile height and width");
sb_Script.AppendLine(" var parHght = $(this).innerHeight();");
sb_Script.AppendLine(" var parWdth = $(this).innerWidth();");
sb_Script.AppendLine();
sb_Script.AppendLine(" // Change tile border (lighten)");
sb_Script.AppendFormat(" $(this).css(\"border-color\", \"{0}\");", group.MetroBorderHighlight);
sb_Script.AppendLine();
sb_Script.AppendLine(" // Check if tile has a slide");
sb_Script.AppendLine(" var chld = $(this).children(\"div\");");
sb_Script.AppendLine(" if (chld != null) {");
sb_Script.AppendLine();
sb_Script.AppendLine(" // Set extended slide and css length for SQUARE and VERTICAL tiles");
sb_Script.AppendLine(" // SQUARE and VERTICAL");
sb_Script.AppendLine(" var extVal = Math.round(parHght * SLIDE_HW_RATIO);");
sb_Script.AppendLine(" extVal = Math.round(extVal * SLIDE_HW_EXT_RATIO) + extVal;");
sb_Script.AppendLine(" var cssAttr = { height: extVal + \"px\", opacity: 1.0 };");
sb_Script.AppendLine(" // HORIZONTAL");
sb_Script.AppendLine(" if ($(this).attr(\"id\").indexOf(\"hTile\") > -1) {");
sb_Script.AppendLine(" var extVal = Math.round(parWdth * SLIDE_HW_RATIO);");
sb_Script.AppendLine(" extVal = Math.round(extVal * SLIDE_HW_EXT_RATIO) + extVal;");
sb_Script.AppendLine(" var cssAttr = { width: extVal + \"px\", opacity: 1.0 };");
sb_Script.AppendLine(" }");
sb_Script.AppendLine();
sb_Script.AppendLine(" // Call JQuery animation method");
sb_Script.AppendLine(" $(chld).animate(cssAttr, 250, \"swing\", function() { });");
sb_Script.AppendLine(" }");
sb_Script.AppendLine(" }");
sb_Script.AppendLine(" });");
sb_Script.AppendLine();
// SlideTile - MouseLeave event function
sb_Script.AppendLine(" $(\"div.slideTile\").mouseleave(function() {");
sb_Script.AppendLine();
sb_Script.AppendFormat(" var SLIDE_HW_RATIO = {0};\n", SLIDE_HW_RATIO.ToString());
sb_Script.AppendLine();
sb_Script.AppendLine(" if (this != null) {");
sb_Script.AppendLine();
sb_Script.AppendLine(" // Get tile height and width");
sb_Script.AppendLine(" var parHght = $(this).innerHeight();");
sb_Script.AppendLine(" var parWdth = $(this).innerWidth();");
sb_Script.AppendLine();
sb_Script.AppendLine(" // Change tile border (back to background color)");
sb_Script.AppendFormat(" $(this).css(\"border-color\", \"{0}\");", group.MetroBorderColor);
sb_Script.AppendLine();
sb_Script.AppendLine(" var chld = $(this).children(\"div\");");
sb_Script.AppendLine(" if (chld != null) {");
sb_Script.AppendLine();
sb_Script.AppendLine(" // Set normal slide length and css for SQUARE and VERTICAL tiles");
sb_Script.AppendLine(" // SQUARE and VERTICAL");
sb_Script.AppendLine(" var extVal = Math.round(parHght * SLIDE_HW_RATIO);");
sb_Script.AppendLine(" var cssAttr = { height: extVal + \"px\", opacity: 0.7 };");
sb_Script.AppendLine(" // HORIZONTAL");
sb_Script.AppendLine(" if ($(this).attr(\"id\").indexOf(\"hTile\") > -1) {");
sb_Script.AppendLine(" var extVal = Math.round(parWdth * SLIDE_HW_RATIO);");
sb_Script.AppendLine(" var cssAttr = { width: extVal + \"px\", opacity: 0.7 };");
sb_Script.AppendLine(" }");
sb_Script.AppendLine();
sb_Script.AppendLine(" $(chld).animate(cssAttr, 250, \"swing\", function() { });");
sb_Script.AppendLine(" }");
sb_Script.AppendLine(" }");
sb_Script.AppendLine(" });");
sb_Script.AppendLine();
// ActiveTile - Click Event (URL ReDirect)
sb_Script.AppendLine(" $(\"div.activeTile\").click(function() {");
sb_Script.AppendLine();
sb_Script.AppendLine(" if (this != null) {");
sb_Script.AppendLine();
sb_Script.AppendLine(" // Get hidden anchor tag from div");
sb_Script.AppendLine(" var chld = $(this).children(\"a\");");
sb_Script.AppendLine(" if (chld != null) {");
sb_Script.AppendLine();
sb_Script.AppendLine(" // Get URL from anchor tag");
sb_Script.AppendLine(" var url = chld.attr(\"href\");");
sb_Script.AppendLine(" window.location.href = url;");
sb_Script.AppendLine(" }");
sb_Script.AppendLine(" }");
sb_Script.AppendLine(" });");
sb_Script.AppendLine();
// End Scripting Section
sb_Script.AppendLine("</script>");
}
catch (Exception ex)
{
throw;
}
return sb_Script.ToString();
}
public Guid TileGroupID { get; set; }
public string ConnectionStringName { get; set; }
}
}
任何幫助將不勝感激!我使用jQuery的V2.0.3和jQuery UI v1.10.3
更新:2013年12月11日 通過所有的網站需要支持的語言運行時,發現下面的(關於上面提到的控制):
Portuguese - Not Working
Russian - Not Working
Chinese (Sim) - WORKING!
English - WORKING!
Czech - Not Working
Dutch - Not Working
French - Not Working
Arabic - WORKING!
German - Not Working
Italian - Not Working
Japanese - WORKING!
Spanish - Not Working
可能的代碼頁問題? (伸展在這裏!)