How to add print button in asp.net

{0 Comments}

If you want add a print button in asp.net, and then you can access JavaScript’s print function through asp.net button.  In first way you can set the print function in on click event of button in designer mode, syntax for that is as follows: but I found it work for html submit tag better then asp.net button, but other method work in fine manner 

 HTML |  copy code |? 
1
<input type="submit" name="Button2" value="Button2" onclick="window.print(); return false;"
2
                id="Submit1" />

Then if you want to set the same attribute from code behind then you can pass value to add function, syntax for the same is as follows:

 C# |  copy code |? 
1
protected void Page_Load(object sender, EventArgs e)
2
    {
3
        Button1.Attributes.Add("onclick", "window.print(); return false");
4
    } 
5

Leave a Comment

Your email address will not be published.