---
title: "Calling .js file function from code behind"  
description: "Calling .js file function from code behind"  
author: "Manoj Bhatt"  
published: 2015-03-25  
updated: 2015-03-25  
canonical: https://www.mindstick.com/forum/23051/calling-js-file-function-from-code-behind  
category: "javascript"  
tags: ["jquery"]  
reading_time: 2 minutes  

---

# Calling .js file function from code behind

I have been [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to call .js file [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) from [code behind](https://www.mindstick.com/forum/2199/call-javascript-s-function-from-code-behind) but function is not being called.

I have this following html [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) which needs to be visible from the code behind.

<input id="btnShowMap" type="button" value="[Results](https://yourviews.mindstick.com/story/4497/usage-of-baking-soda-magical-results) On Map" [onclick](https://www.mindstick.com/forum/12718/onclick-for-hyperlink) = "ShowMap();" [style](https://www.mindstick.com/articles/126300/apa-citation-style-get-to-know-about-it-for-your-next-assignment)="[visibility](https://www.mindstick.com/blog/301300/how-to-improve-your-visibility-in-zero-click-search-results): [hidden](https://www.mindstick.com/forum/2303/skip-validating-field-from-hidden-div);"/>

**I have tried following three [methods](https://www.mindstick.com/articles/13060/runny-nose-remedy-methods-that-work-best) so far and none of them is working.**

-ClientScript.RegisterStartupScript(Me.GetType(), "VoteJsFunc", "test();")

-Page.ClientScript.RegisterStartupScript(Me.[GetType](), "VoteJsFunc", "alert('Sorry.You are not legible to vote')", True)

-ClientScript.RegisterStartupScript(Me.GetType(), "VoteJsFunc", "test();")

## Here is .js file function

```
function test() {var hdLat = $('input[id$=hdVendorLat]').val();    var hdLng = $('input[id$=hdVendorLng]').val();    if (hdLat != 0 && hdLng != 0) {        $('#btnShowMap').show();    }    else {        $('#btnShowMap').hide();    } }
```

## Here is the pahe html

```
 <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> </asp:Content>  <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"><asp:UpdatePanel ID="updSearch" UpdateMode="Conditional" runat="server">    <Triggers>        <asp:AsyncPostBackTrigger ControlID="btnSearch" />    </Triggers>    <ContentTemplate>        <asp:HiddenField ID="hdVendorLat" runat="server" Value="0" />        <asp:HiddenField ID="hdVendorLng" runat="server" Value="0" />        <asp:HiddenField ID="hdVenID" runat="server" Value="" />  <asp:Panel ID="pnlExport" runat="server" Enabled="true">        <asp:Button ID="btnSearch" runat="server" Text="Search" Width="90px" />                            <input id="btnShowMap" type="button" value="Results On Map" onclick   = "ShowMap();" style="visibility: hidden;"  /></asp:Panel> <script type="text/javascript" src="/scripts/inspector-search.js"></script>    </ContentTemplate></asp:UpdatePanel></asp:Content>
```

## Replies

### Reply by Anonymous User

Query method show works over display css property. It is equivalent to call .css( "display", "block").

Since you are using visibility property, method show has no effect on changing this so it remains hidden. I see 2 options to fix this:

use .css( "visibility", "visible") instead of .show()

replace style="visibility: hidden;" by style="display: none" on your input markup


---

Original Source: https://www.mindstick.com/forum/23051/calling-js-file-function-from-code-behind

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
