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?

function Test()
alert('Calling this function in Codebehind')

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
    Last 7 Daysmore...

    Awards & Gifts

    Online Members

    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India