Calling & Writing Javascript Function From Server Side Code Behind & From Html

Calling & Writing Javascript Function From Server Side Code Behind & From Html

Writing JavaScript function in server side code behind and calling from HTML

//Server Side
private void Page_Load(object sender, System.EventArgs e)
{
    string jScriptStr;
    jScriptStr=”<script>function JavScriptFn(){alert” +
      ” (’Client Function in javascript is call’)}</script>”;
}

//HTML side
< A onclick=”JavScriptFn()” >
< asp:Label id=”Label1″ runat=”server” Width=”281px”
   ForeColor=”#8080FF”>Click to call Javascript function.
</asp:Label></A >

Writing JavaScript in HTML and calling it from code-behind

//Html side 

<Head >

        <script>
        
        function ReqField1Validator()
        {
         if (document.forms[0].txtField1.value == ‘’)
            {
                alert(’TextBox cannot be empty’)
                return false
            }
                return true
        } 
                
        </script>
    </Head >

//Server Side 

private void Page_Load(object sender, System.EventArgs e)
{
    btnOK.Attributes.Add(”onclick”,”return ReqField1Validator()”);
}

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.