0

按下浏览器后退按钮后,无法在页面加载时读取选定的下拉列表值。但这仅在第一次函数调用期间发生。我将详细解释:最初加载页面时,我附加了一个 ajax javascript,如下所示

this.Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", "_Initialize_Chart();", true);

下面是javascript AJAX函数

    function _Initialize_Chart() {

    var selectedDeptId = $(ddlQueues).val();
    var selectedMonth = $(ddlMonth).val();
    var selectedYear = $(ddlYear).val();
    $.ajax({
        type: "GET",
        url: ajaxCallHandlerUrl,
        data: {
            OpCode: "GetCallAverageMonthlyReportForGraph",
            Params: "DeptId^" + selectedDeptId + "~Month^" + selectedMonth + "~Year^" + selectedYear
        },
        dataType: "xml",
        beforeSend: function () {
            $('#' + lblCallAverageDetails).html('');
            document.getElementById(chartdiv).style.backgroundImage = "url('../images/ajax-loader_new_.gif')";
        },
        success: function (responseString) {
            document.getElementById(chartdiv).style.backgroundImage = "";
            _Load_Chart(responseString);
            _Load_CallAverageGridData();
        },
        error: function (xhr, errorType, exception) {
            var errorMessage = exception || xhr.statusText;
            alert("There was an error Initializing Charts :: " + errorMessage);
        }
    });
}


    function _Load_CallAverageGridData() {
    var selectedDeptId = $(ddlQueues).val();
    var selectedMonth = $(ddlMonth).val();
    var selectedYear = $(ddlYear).val();
    $.ajax({
        type: "GET",
        url: ajaxCallHandlerUrl,
        data: {
            OpCode: "GetCallAverageReportDetail",
            Params: "DeptId^" + selectedDeptId + "~Month^" + selectedMonth + "~Year^" + selectedYear
        },
        dataType: "",
        success: function (responseString) {
            $('#' + lblCallAverageDetails).html(responseString);
        },
        error: function (xhr, errorType, exception) { //Triggered if an error communicating with server  
            var errorMessage = exception || xhr.statusText; //If exception null, then default to xhr.statusText  
            alert("There was an error Fetching Call Average Data :: " + errorMessage);
        }
    });
}

所以这个 javascript 加载页面内容,它是一个图形和一个网格。单击网格中的行时,它会导航到另一个页面。现在按下浏览器后退按钮时,最初调用了上面显示的 javascript,但 var selectedMonth = $(ddlMonth).val();没有给我下拉列表中实际选择的值的值。在第一次 Ajax 调用成功时,会进行另一个 Ajax 调用_Load_CallAverageGridData();,在该调用中我得到了var selectedMonth = $(ddlMonth).val();正确的值。任何人都可以阐明为什么会发生这种情况。

4

1 回答 1

0

您在页面加载中的代码

 this.Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", "_Initialize_Chart();", true);

不在页面加载时执行,要执行它,您需要使用 url 哈希函数。因为它只是使用这个

您在页面上单击产品/图像的位置调用 onclick javascript 函数,即

function getHashOnBack(valueget) 
{
   location.hash = "#backTo=" + $(window).scrollTop();$(document).height();
}

现在,放

$(document).ready(function () 
{
var ab = window.location.hash.substring(1).split("=");
if (ab[0] == "backTo") 
{
 // this would be called automatically when back putton pressed and hav #back=1234   etc. // value in url

 $(window).scrollTop(parseInt(ab[1]));
}
}
于 2013-05-01T12:50:46.550 回答