Hi indradeo
Please refer below sample.
HTML
<table border="1" class="auto-style43">
<tr>
<td class="auto-style75">
<img src="images/m1.png" alt="Capture" class="auto-style42" />
</td>
<th class="auto-style46" style="box-sizing: border-box;" colspan="4">
<span class="auto-style44">Meja Thermal Power Plant<br />
<span style="color: rgb(0, 0, 0); font-family: Roboto; font-size: 15px; font-variant-ligatures: normal;
font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: center;
text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;
-webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial;
text-decoration-style: initial; text-decoration-color: initial; display: inline !important;
float: none;">A Joint Venture of NTPC Ltd & UPRVUNL</span></span><br class="auto-style44" />
</th>
</tr>
<tr>
<td class="auto-style100">
</td>
<th class="auto-style101" style="box-sizing: border-box;" colspan="4">
<font style="box-sizing: border-box;"><span class="auto-style45">VISITOR GATE PASS </span>
</font>
</th>
</tr>
<tr>
<td class="auto-style63" rowspan="2">
<img id="imgCapture" src="images/m1.png" alt="Capture" />
</td>
<th class="auto-style68" style="box-sizing: border-box;" colspan="3">
Visitor Id:
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</th>
<th class="auto-style88">
Visitor Aadhar No. :
<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
</th>
</tr>
<tr>
<th class="auto-style83" style="box-sizing: border-box;" colspan="3">
Visitor Name :
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
</th>
<th class="auto-style84">
Gender :
<asp:Label ID="Label7" runat="server" Text="Label"></asp:Label>
</th>
</tr>
<tr>
<th class="auto-style98" style="box-sizing: border-box;">
Father/Husband Name:
</th>
<th class="auto-style114" style="box-sizing: border-box;">
<asp:Label ID="Label6" runat="server" Text="Label"></asp:Label>
</th>
<th class="auto-style96" colspan="2">
Current Address :
</th>
<th class="auto-style97">
<asp:Label ID="Label8" runat="server" Text="Label"></asp:Label>
</th>
</tr>
<tr>
<th class="auto-style94" style="box-sizing: border-box;">
Purpose of visit :
</th>
<th class="auto-style54" style="box-sizing: border-box;" colspan="3">
<asp:Label ID="Label9" runat="server" Text="Label"></asp:Label>
</th>
<th class="auto-style72">
</th>
</tr>
<tr>
<th class="auto-style91" style="box-sizing: border-box;">
Emp.Name:
</th>
<th class="auto-style108" style="box-sizing: border-box;">
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</th>
<th class="auto-style103">
Emp. ID :
</th>
<th class="auto-style113">
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
</th>
<th class="auto-style93">
Department :<asp:Label ID="Label12" runat="server" Text=""></asp:Label>
</th>
</tr>
<tr>
<th class="auto-style99">
Gate pass Cretion Date/Time:
</th>
<th class="auto-style117" colspan="3">
<asp:Label ID="Label10" runat="server" Text="Label" CssClass="auto-style106"></asp:Label>
</th>
<th class="auto-style116">
</th>
</tr>
<tr>
<th height="120" colspan="2" class="auto-style73" style="height: 60px">
CISF Signature
</th>
<th height="120" colspan="3" class="auto-style73" style="height: 60px">
Employee Signature
</th>
</tr>
<tr>
<th colspan="5" class="auto-style73">
<div class="noprint">
<input id="btnCapture" type="button" value="Image Capture" />
<asp:Button ID="btnPrint" runat="server" Text="Print" Height="27px" Width="53px"
OnClientClick="return Print();" />
<asp:Button ID="Button1" runat="server" Text="Back" CssClass="auto-style81" CausesValidation="false"
Height="28px" OnClick="Button1_Click" Width="81px" />
</div>
</th>
</tr>
</table>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function Print() {
$.ajax({
type: "POST",
url: "Default.aspx/PrintName",
data: "{name :' " + $('[id*=Label1]').html() + " ', customerId:' " + $('[id*=Label3]').html() + " '}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert(response.d);
window.print();
},
error: function (response) {
alert(response.responseText);
}
});
return false;
};
</script>
Namespaces
C#
using System.IO;
using System.Data;
using System.Web.Services;
using System.Data.SqlClient;
using System.Configuration;
VB.Net
Imports System.IO
Imports System.Data
Imports System.Web.Services
Imports System.Data.SqlClient
Imports System.Configuration
Code
C#
int customer = 0;
protected void Page_Load(object sender, EventArgs e)
{
//customer = Convert.ToInt32(Request.QueryString["CustomerId"].ToString());
Session["EmpId"] = customer;
if (!IsPostBack)
{
BindTextBoxvalues();
}
}
[WebMethod]
public static string PrintName(string name, string customerId)
{
string constring = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("UPDATE Customers SET Name = @Name WHERE CustomerId=@CustomerId", con))
{
cmd.Parameters.AddWithValue("@Name", name.Trim());
cmd.Parameters.AddWithValue("@CustomerId", customerId.Trim());
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
return "Thanks for Using Visitor Gate Pass System. Please Click OK !!!!";
}
private void BindTextBoxvalues()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand("select * from Customers where CustomerId=" + customer, con);
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("cisf.aspx");
}
VB.Net
Private customer As Integer = 0
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
'customer = Convert.ToInt32(Request.QueryString("CustomerId").ToString())
Session("EmpId") = customer
If Not IsPostBack Then
BindTextBoxvalues()
End If
End Sub
<WebMethod()>
Public Shared Function PrintName(ByVal name As String, ByVal customerId As String) As String
Dim constring As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(constring)
Using cmd As SqlCommand = New SqlCommand("UPDATE Customers SET Name = @Name WHERE CustomerId=@Id", con)
cmd.Parameters.AddWithValue("@Name", name.Trim())
cmd.Parameters.AddWithValue("@Id", customerId.Trim())
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Using
End Using
Return "Thanks for Using Visitor Gate Pass System. Please Click OK !!!!"
End Function
Private Sub BindTextBoxvalues()
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim con As SqlConnection = New SqlConnection(constr)
Dim cmd As SqlCommand = New SqlCommand("select * from Customers where CustomerId=" & customer, con)
Dim dt As DataTable = New DataTable()
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
da.Fill(dt)
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Response.Redirect("cisf.aspx")
End Sub
Screenshot