Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai
How to pass msg from server side to javascript and show in alert msg ?
actuall i will use in this code in server side to call javascript and show alert msg

VB
If Not ClientScript.IsClientScriptBlockRegistered("afterDownload") Then
ClientScript.RegisterClientScriptBlock(Me.GetType, "afterDownload", "testmsg()", True)
End If


and in javascript is
JavaScript
  var frameTimer;
        function testmsg() {

            if (frameTimer != null) {
                clearInterval(frameTimer);
            }
            var hiddenFrame = document.getElementById("hiddenFrame");
            if (hiddenFrame == null) {
                frameTimer = setTimeout("testmsg()", 800);
                return;
            }


          
            alert("Hello World");
}


the above code work correctly and show "Hello world" alert msg,but my need is pass msg in testmsg() and show in alert msg.that is need to change message
Posted

1 solution

Code:[Convert to VB if required]
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert", "<script type='text/javascript'>testmsg('This is the alert you want');</script>", false);
JavaScript:
C#
<script type="text/javascript">
    function testmsg(msg) {

       alert(msg);
    }
</script>
 
Share this answer
 
v2
Comments
Aravindba 18-Nov-13 1:44am    
thank u for ur reply ,it work fine,but no need to check If Not ClientScript.IsClientScriptBlockRegistered("afterDownload") Then ?
if it is not have if condition it will work,thanxs a lot...
Thanks7872 19-Nov-13 22:48pm    
Try this:
testmsg('" & msg & "');
Aravindba 20-Nov-13 1:41am    
thanx it will,but i use testmsg('"+ msg +"') both are working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900