Click here to Skip to main content
15,908,843 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
I have tried using this.

 <script language="javascript" type="text/javascript">

        function print() {
            window.print();
        }
    </script>
In code behind:

    protected void Page_Load(object sender, EventArgs e)
    {
      ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "script", "print()", true);
    }
But it is not working.please help me.

C#

Posted
Comments
shwetabtp 21-Nov-14 7:52am    
It should be

ScriptManager.RegisterStartupScript(this,this.GetType(), "Javascript", "javascript:print();", true);

1 solution

Try the below with similar solution

http://stackoverflow.com/questions/14079029/how-to-call-javascript-function-on-page-load-in-asp-net[^]

I created a sample and code flow reaches the javascript function on page load event.

C#
protected void Page_Load(object sender, EventArgs e)
       {
           ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript:print(); ", true);
       }



XML
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script lang="javascript" type="text/javascript">

        function print() {
            // window.print();
            alert('hello');
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900