Tutorials » Javascript tutorials »

How to call JavaScript from code behind?


This article explains calling Javascript from Codebehind


Many a times I see repeatedly asked question in forums is how do we call Javascript from codebehind?

<script>
function Test()
{
alert('Calling this function in Codebehind')
}
</script>

In order to call Test() in page_load event of codebehind file ,I mean Cs /vb file
Button1.Attributes.Add("onclick", " return Test();");

This will call Javascript from serverside when the corresponding event is fired.
Javascript in codebehond

To Use confirm message directly from codebehind
btnSubmit.Attributes.Add("onclick", "if(!confirm('Are you sure?')) return false;")




Previous Chapter: Playing with window events
More Chapters: Javascript Tutorials
More Tutorials: Tutorial Index



Top Contributors
Today
    Last 7 Daysmore...

    Awards & Gifts

    Online Members

    VELIDIRAVIRAM
    More...
     
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India