Code : Add a JavaScript function on default.aspx page under head tag.
//*
<script type="text/javascript" language="javascript">
function helloWorld(){
alert("welcome to startcoding.in");
}
</script>
//*
Server-side: using the below-given code we are able to call the JavaScript function from the server-side.
//*
ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript:FUNCTIONNAME(); ", true);
//*
as our JavaScriptript function name as helloWorld() so our final code would be like as given below
//*
ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript:helloWorld(); ", true);
//*
If you have used Asp.net UpdatePanel in your Design page (.aspx page ) then the code will be like
//*
ScriptManager.RegisterStartupScript(GetType(), "Javascript", "javascript:FUNCTIONNAME(); ", true);
//as our javascript function name as helloWorld() so we write this code as
ScriptManager.RegisterStartupScript(GetType(), "Javascript", "javascript:helloWorld(); ", true);
//*
Thank you for reading, pls keep visiting this blog and share this in your network. Also, I would love to hear your opinions down in the comments.
PS: If you found this content valuable and want to thank me? 👳 Buy Me a Coffee
Post Comment
Your email address will not be published. Required fields are marked *