Hi firoz1986,
I have created sample code which full-fill your requirement. So please refer the below code.
HTML
<div>
<table>
<tr>
<td>
<asp:Button ID="btnSubmit" Text="Login" OnClick="Submit" runat="server" />
</td>
</tr>
</table>
</div>
C#
protected void Submit(object sender, EventArgs e)
{
Response.Redirect("Default2.aspx");
}
Vb.net
Protected Sub Submit(sender As Object, e As EventArgs)
Response.Redirect("Default2.aspx")
End Sub
View Page
HTML
<form id="form1" runat="server">
<div>
<h1>
Plan A Trip to Georgia
</h1>
<div style="margin-bottom: 15px; margin-left: 20px">
<span class="glyphicon glyphicon-calendar">06/07/2017 1:40:10PM</span> <span
class="glyphicon glyphicon-tag">Family</span> <span class="glyphicon glyphicon-eye-open">
<asp:Label ID="lblViews" Text="0" runat="server" />
</span>
</div>
<div style="margin-bottom: 15px; margin-left: 20px">
<asp:Image ImageUrl="~/Image.jpg" runat="server" />
</div>
</div>
<asp:Button Text="Back" OnClick="OnBack" runat="server" />
<div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
</div>
</form>
C#
private string constring = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.GetViews();
this.Views();
}
}
private void Views()
{
SqlConnection con = new SqlConnection(constring);
SqlCommand cmd = new SqlCommand("Update [Likes] SET [Count]=@Views", con);
cmd.Parameters.AddWithValue("@Views", Convert.ToInt32(lblViews.Text.Trim()));
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
private void GetViews()
{
SqlConnection con = new SqlConnection(constring);
SqlCommand cmd = new SqlCommand("SELECT * FROM [Likes]", con);
con.Open();
SqlDataReader idr = cmd.ExecuteReader();
if (idr.Read())
{
lblViews.Text = (Convert.ToInt32(idr["LikeCount"].ToString()) + 1).ToString();
}
con.Close();
}
protected void OnBack(object sender, EventArgs e)
{
Response.Redirect("Default.aspx");
}
Vb.Net
Private constring As String = ConfigurationManager.ConnectionStrings("constring").ConnectionString
Protected Sub Page_Load(sender As Object, e As EventArgs)Handles Me.Load
If Not IsPostBack Then
Me.GetViews()
Me.Views()
End If
End Sub
Private Sub Views()
Dim con As New SqlConnection(constring)
Dim cmd As New SqlCommand("Update [Likes] SET [Count]=@Views", con)
cmd.Parameters.AddWithValue("@Views", Convert.ToInt32(lblViews.Text.Trim()))
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Sub
Private Sub GetViews()
Dim con As New SqlConnection(constring)
Dim cmd As New SqlCommand("SELECT * FROM [Likes]", con)
con.Open()
Dim idr As SqlDataReader = cmd.ExecuteReader()
If idr.Read() Then
lblViews.Text = (Convert.ToInt32(idr("LikeCount").ToString()) + 1).ToString()
End If
con.Close()
End Sub
Protected Sub OnBack(sender As Object, e As EventArgs)
Response.Redirect("Default.aspx")
End Sub
Screenshot
