使用__doPostBack和JQuery可能出错

时间:2012-06-20 19:13:49

标签: javascript jquery asp.net dotnetnuke dopostback

我正在尝试使用__doPostBack将一些数据从客户端传递到服务器端。我不是很熟悉JS,但是在使用Firebug进行调试时,发生了一些奇怪的事情。我会先显示我的代码。

<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;
}

最终发生的是我点击链接按钮并且firebug跳转到第一行代码,但在它甚至完成该功能之前它突然跳转到__doPostBack函数的代码,直到我传入变量。为什么会这样?

我还应该提一下,如果这有所作为,我会在DNN中这样做。我认为问题可能是我形成jquery函数的方式或者我如何调用它。

1 个答案:

答案 0 :(得分:1)

发现问题。我只需要移动我的jquery放在代码中的位置。我认为它不在某个括号内,因此无法看到数据。缺乏intellisense和无序的代码再次打击!现在编写下载功能。