CALLING .JS FILE FUNCTION FROM CODE BEHIND

Manoj Bhatt

Total Post:154

Points:1086
Posted by  Manoj Bhatt
JQuery 
 823  View(s)
Ratings:
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) {

        $('#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>

  1. Ankita Pandey

    Post:183

    Points:1285
    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!