Hi abualmazen,
Check this example. Now please take its reference and correct your code.
HTML
<asp:Label ID="lblTest" Text="Welcome to AspForums!" runat="server" />
<asp:Button ID="btnPrint" runat="server" Text="Print" OnClick="Print" />
Namespaces
C#
using System.Drawing.Printing;
using System.Drawing;
VB.Net
Imports System.Drawing.Printing
Imports System.Drawing
Code
C#
void pd_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawString(lblTest.Text, new System.Drawing.Font("Arial", 12), new SolidBrush(Color.Blue), 10, 10);
}
protected void Print(object sender, EventArgs e)
{
try
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.Print();
}
catch (Exception ex)
{
Response.Write(ex.Message);
Response.End();
}
}
VB.Net
Private Sub pd_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
e.Graphics.DrawString(lblTest.Text, New System.Drawing.Font("Arial", 12), New SolidBrush(Color.Blue), 10, 10)
End Sub
Protected Sub Print(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim pd As PrintDocument = New PrintDocument
AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
pd.Print()
Catch ex As Exception
Response.Write(ex.Message)
Response.End()
End Try
End Sub
Screenshot
