how to pass the strMessage (from codebehind to the script) to get the alert message
i.e
if my strmessage from code behind is hi,
then i need
You Have Used already the message : hi
My code…
<script type="text/javascript">
var strFileName;
function alertShowMessage() {
alert("You Have Used already the message :"+ <%=strFileName %>+ ");
}
</script>
datatable dtChkFile =new datatable();
dtChkFile = objutility.GetData("ChkFileName_SMSSent", new object[] {"rahul"}).Tables[0];
if (dtChkFile.Rows.Count > 0)
{
for (int i = 0; i < dtChkFile.Rows.Count; i++)
{
strMessage= dtChkFile.Rows[i]["Message"].To);
}
}
Depending on at what point you want the alert message to appear, consider using RegisterStartupScript / RegisterClientScriptBlock. Here’s a sample (also using the AntiXSS library to javascript-encode the word to mitigate against quotes or any kind of XSS attack).