Hi vrindavani,
Update panels have their UpdateMode property set to Always by default. So they will fire on any post back even from another update panel.
So you need to set UpdateMode to Conditional and ChildrenAsTriggers as false.
Also you need to assigh AsyncPostBackTrigger.
Conditional will update only if a child control or child update panel is triggering the PostBack.
Check this example. Now please take its reference and correct your code.
HTML
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="Upd" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<h2>Youtube Video</h2>
<div class="sports-news mb60 well">
<div class="sports-title mb20">
<h4>Bowie talking</h4>
</div>
<div class="sports-img zoom mb60">
<iframe width="200" height="150" src="https://www.youtube.com/embed/cWuvnc6u93A"
frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen></iframe>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel3" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
Start Time :<asp:Label ID="lblStartTime" Text="" runat="server" BackColor="#CC0000"
BorderColor="#FFFF99" BorderStyle="Solid" Font-Bold="True" ForeColor="White"
Height="25px" Width="144px"></asp:Label>
<br />
End Time :<asp:Label ID="lblEndTime" Text="" runat="server" BackColor="#CC0000"
BorderColor="#FFFF99" BorderStyle="Solid" Font-Bold="True" ForeColor="White"
Height="25px" Width="144px"></asp:Label>
<br /><br />
<asp:Button ID="btnStartStop" Text="Start" runat="server" CssClass="btn btn-primary"
OnClick="OnStartStop" Font-Bold="True" Height="50px" Width="100px" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnStartStop" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
Namespaces
C#
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
VB.Net
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Code
C#
protected void OnStartStop(object sender, EventArgs e)
{
DateTime startTime = DateTime.Now;
if (btnStartStop.Text == "Start")
{
btnStartStop.Text = "Stop";
lblStartTime.Text = startTime.ToString("HH:mm:ss");
}
else if (btnStartStop.Text == "Stop")
{
btnStartStop.Text = "Start";
DateTime endTime = DateTime.Now;
lblEndTime.Text = endTime.ToString("HH:mm:ss");
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conString"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO Times VALUES(@Start,@Stop)", con))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Start", lblStartTime.Text);
cmd.Parameters.AddWithValue("@Stop", lblEndTime.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
}
VB.Net
Protected Sub OnStartStop(ByVal sender As Object, ByVal e As EventArgs)
Dim startTime As DateTime = DateTime.Now
If btnStartStop.Text = "Start" Then
btnStartStop.Text = "Stop"
lblStartTime.Text = startTime.ToString("HH:mm:ss")
ElseIf btnStartStop.Text = "Stop" Then
btnStartStop.Text = "Start"
Dim endTime As DateTime = DateTime.Now
lblEndTime.Text = endTime.ToString("HH:mm:ss")
Using con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("conString").ConnectionString)
Using cmd As SqlCommand = New SqlCommand("INSERT INTO Times VALUES(@Start,@Stop)", con)
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("@Start", lblStartTime.Text)
cmd.Parameters.AddWithValue("@Stop", lblEndTime.Text)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Using
End Using
End If
End Sub
Screenshot