我需要为POP-UP窗口设置焦点,以便屏幕阅读器两次读取错误消息。
if (Convert.ToDateTime(txtFromDate.Text.Trim()).DayOfWeek != DayOfWeek.Monday)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "PopUp", "alert('Previous week start date should be a Monday !');", true);
return;
}
答案 0 :(得分:0)
您可以使用以下代码重新加载。将以下脚本添加到aspx页面。然后,在您的代码隐藏中调用函数showAlert()
而不是原始的启动脚本。
代码隐藏
if (Convert.ToDateTime(txtFromDate.Text.Trim()).DayOfWeek != DayOfWeek.Monday)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "PopUp", "showAlert()", true);
return;
}
JavaScript
<script>
function showAlert() {
alert('Previous week start date should be a Monday !');
if (getCookie("reloadPage") === "2" || getCookie("reloadPage") === "")
{
setCookie("reloadPage", "1",1);//create a persistent cookie
window.location.reload(true);
} else if(getCookie("reloadPage") === "1") {
setCookie("reloadPage", "2",1);//create a persistent cookie
}
}
function setCookie(cname, cvalue, exdays) {
try {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires + ";path=/";
} catch (e) { }
}
function getCookie(cname) {
try {
var name = cname + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
}
} catch (e) { }
return "";
}
</script>