how to call javascript function in c#

Forums C#how to call javascript function in c#
Staff asked 1 year ago

Answers (1)

Add Answer
Ashmita Marked As Accepted
Staff answered 1 year ago

HTML markup showing a label and button control is as follows.

<body> 
  <form id="form1" runat="server"> 
  <div> 
    <asp:Label ID="lblJavaScript" runat="server" Text=""></asp:Label> 
    <asp:Button ID="btnShowDialogue" runat="server" Text="Show Dialogue" /> 
  </div> 
  </form> 
</body>


JavaScript Function
<head runat="server"> 
  <title>Calling javascript function from code behind example</title> 
  <script type="text/javascript"> 
    function showDialogue() { 
      alert("this dialogue has been invoked through codebehind."); 
    } 
  </script> 
</head>

Code trigger the javascript function
lblJavaScript.Text = "<script type='text/javascript'>showDialogue();</script>";

Subscribe

Select Categories