forum

Home / DeveloperSection / Forums / Calling .js file function from code behind

Calling .js file function from code behind

Manoj Bhatt 1877 25-Mar-2015

I have been trying to call .js file function from code behind but function is not being called. 

I have this following html button which needs to be visible from the code behind. 

   <input id="btnShowMap" type="button" value="Results On Map" onclick = "ShowMap();" style="visibility: hidden;"/>

I have tried following three methods 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>

Updated on 25-Mar-2015

Can you answer this question?


Answer

1 Answers

Liked By