0
我想使用__doPostBack將一些數據從客戶端傳遞到服務器端。我並不是很熟悉JS,但是在Firebug中進行調試時發生了一些奇怪的事情。我會先顯示我的代碼。可能的錯誤使用__doPostBack和JQuery
<script type="text/javascript">
function BeginDownload() {
var temp = $("#waterwheel-carousel-horizon").CurrentSelectedImg().toString()
__doPostBack("ImgDownload", temp);
}
</script>
下面是我試圖調用的相關jQuery。
// Relevant Waterwheel jquery code.
$.fn.CurrentSelectedImg = function() {
return data.currentCenterItem.data().index; };
$.fn.waterwheelCarousel = function (options) {
// override the default options with user defined options
options = $.extend({}, $.fn.waterwheelCarousel.defaults, options || {});
return $(this).each(function() {
/* These are univeral values that are used throughout the plugin. Do not modify them
* unless you know what you're doing. Most of them feed off the options
* so most customization can be achieved by modifying the options values */
var data = {
itemsContainer: $(this).find(".carousel-images"),
totalItems: $(this).find(".carousel-images img").length,
containerWidth: $(this).width(),
containerHeight: $(this).height(),
currentCenterItem: null,
items: [],
itemDistances: [],
waveDistances: [],
itemWidths: [],
itemHeights: [],
itemOpacities: [],
carouselRotationsLeft: 0,
currentlyMoving: false,
itemsAnimating: 0,
currentSpeed: options.speed,
intervalTimer: null
};
// Setup the carousel
beforeLoaded();
// Preload the images. Once they are preloaded, the passed in function
// will be called and the carousel will be setup
preload(function() {
setupDistanceArrays();
setupCarousel();
setupStarterRotation();
});
和幕後的代碼。目前尚未達成目標。
// This code is currently not reached, but I put it here for completion.
#region EventTarget
private string EventTarget
{
get{
return Request.Form["__EVENTTARGET"].ToString().ToUpper();
}
}
#endregion EventTarget
#region HandlePostBack
void HandlePostBack()
{
switch (EventTarget)
{
case "ImgDownload":
DownloadImage(EventArgs);
break;
}
}
#endregion HandlePostBack
private void DownloadImage(string index)
{
string test = index;
}
最終發生的事情是我點擊的LinkButton和螢火蟲跳轉到第一行代碼,但即使完成該功能前突然跳到__doPostBack函數的代碼之前,我甚至在傳遞變量。這是爲什麼發生?
我還應該提到我在DNN中這樣做,如果這有所作爲。我認爲這個問題可能是我形成jquery函數的方式,或者我如何調用它。
順便說一句......我注意到你在你的EventTarget屬性中使用ToUpper(),但不在switch語句中...... –
我剛剛發現了這一點。不過謝謝。我認爲JS在我的CurrentSelectedImg調用中崩潰。我可能有一個畸形的功能,但我不知道。 – Mitchell
數據定義在哪裏? –