Tuesday, January 24, 2017

Javascript/Jquery to Hide link button: Asp.net C#


##Add Script to the aspx page as shown below,get value from Session,if available then disable or remove the reference link.


/* .aspx page */
 
<script type="text/javascript">

  jQuery(document).ready(function ($) {
        var value = '<%=Session["SomeValue"]%>';
       // alert("hi1");
        if (value) {
          //  alert("hi");

            //$("#ctl00__lnkCart").attr("disabled", "disabled");
            $("#ctl00__lnkCart")[0].href = "javascript:void(0)"; //Remove url
        }
        else {
        
           $("#ctl00__lnkCart")[0].href="www.google.com";// pass url
        }

    });

</script>

  <asp:HyperLink ID="lnkCart" runat="server" >

/* .aspx.cs page */

   Session["SomeValue"] = "SomeValue";

####Cart button is disabled based on session value.