Calling .js file function from code behind

Total Post:154


 1426  View(s)
Rate this:

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) {
    else {

Here is the pahe html 

 <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:UpdatePanel ID="updSearch" UpdateMode="Conditional" runat="server">
        <asp:AsyncPostBackTrigger ControlID="btnSearch" />
        <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;"  />
<script type="text/javascript" src="/scripts/inspector-search.js"></script>
  1. Re: Calling .js file function from code behind

    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

      Modified On Mar-25-2015 07:46:28 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.