用于从代码隐藏中触发JavaScript代码的代码片段(在C#中)如下:
int returnValue = SaveStudent("John", "XII"); // SaveStudent() is a C# function that saves the student details in DB and returns studentId.
hdnStudentId = returnValue ; // hdnStudentId is a hidden-field control
ScriptManager.RegisterStartupScript(this, this.GetType(),
"ShowStudent", "showStudentDetails();",true);
“showStudentDetails()”JavaScript方法的定义如下:
function showStudentDetails(){
If($('[id*=hdnStudentId]').val() > 0){
// show the popup
}
}
以下是问题的描述:
要求:当用户点击“浏览器后退按钮”时,我们还需要记住DOM中先前操作过的数据(即$('[id * = hdnStudentId]')。val(' - 1');)以便我们可以避免在浏览器后退按钮上显示弹出窗口。
您需要检查浏览器历史记录API,以便在没有服务器时保存您的页面状态,这里是mdn doc https://developer.mozilla.org/en-US/docs/Web/API/History_API
DOM
window
对象通过history
对象提供对浏览器历史的访问。它公开了有用的方法和属性,让您可以在用户的历史记录中来回移动,以及 - 从HTML5开始 - 操作历史堆栈的内容
以及Ajax导航https://developer.mozilla.org/en-US/docs/Web/API/History_API/Example的一个例子。希望有所帮助!
谢谢@Salus ...我听了你的建议..最后,以下代码片段为我工作..我使用'history.pushState();'显示弹出窗口后的方法:
$('#divStudentDetails').modal('show');
history.pushState(null, null, "");