I've been working on a JavaScript function that displays error messages. But I'm facing an issue where even after trying to clear the label, the original text in AlertLiteral remains unchanged.
<script type="text/javascript">
<!--
var errMessage = '';
function ShowError() {
var options = {};
if (arguments.length == 1)
options = arguments[0];
var title = '<%= AlertTitle.Text.Replace("'", "\'") %>';
errMessage = $('#<%= AlertLiteral.ClientID %>').html().replace(/\\'/g, "'");
$('#<%= AlertLiteral.ClientID %>').html('');
}
$("#errDlgText").html(errMessage);
if (options.title != undefined)
title = options.title;
var focusOn = null;
if (options.setFocus != undefined)
focusOn = options.setFocus;
var onOK = null;
if (options.onOK != undefined)
onOK = options.onOK;
if (errMessage == '')
return;
$("#errDialog").dialog({
modal: true,
buttons: {
OK: function() {
if (onOK != null)
onOK();
errMessage = '';
$('#<%= AlertLiteral.ClientID %>').html('');
$(this).dialog('close');
}
},
title: title,
close: function () {
errMessage = '';
$('#<%= AlertLiteral.ClientID %>').html('');
if (focusOn != null)
focusOn.focus();
}
});
}
//-->
</script>
When trying to debug this issue, I noticed that AlertLiteral was not getting emptied as expected. Could someone kindly shed some light on what could be causing this inconsistency?