Tuesday, December 10, 2013

Call Jquery function from code behind



Below are the code for calling jquery function from asp.net code behind   

protected void Button_Click(object sender, EventArgs e)
    {
        string myScriptValue = "$(document).ready(function(){"+
          "your jquery code here”+
        "}); ";

        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "myScriptName", myScriptValue, true);

   
    }

Print image from javascript




The below are the javascript function for print the image
 
<script type="text/javascript">
        function printImage() {
            var image = document.getElementById('imageControl');
            var printWindow = window.open('', 'Print Window', 'height=400,width=600');
            printWindow.document.write('<html><head><title>Print Window</title>');
            printWindow.document.write('</head><body ><img src=\'');
            printWindow.document.write(image.src);
            printWindow.document.write('\' /></body></html>');
            printWindow.document.close();
            printWindow.print();
        }
  </script>


Call the javascript function from below code 

<a id="link" style="font-size:2em" onclick="printImage()" href="#">
<img src="Images/print.png" />
</a>