I have onclientclick and onclick events written for Exit button on my webpage. When clicked, it should first execute the update statement and then close the window.
<asp:Button ID="ExitButton" runat="server" OnClientClick="javaScript:self.close(); return false;" OnClick="ExitButton_Click" UseSubmitBehavior="false" Text="Exit" Width="102px" CssClass="CssStyle2" Height="29px" />
protected void ExitButton_Click(object sender, EventArgs e)
{
string sqlUpd = @"UPDATE top (2) [db1].[TestTable] set flag=0
where Date is null and flag=-1";
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLConnectionString"].ConnectionString))
{
connection.Open();
SqlCommand cmdUpd = new SqlCommand(sqlUpd, connection);
try
{
Int32 rows = cmdUpd.ExecuteNonQuery();
connection.Close();
}
catch (Exception eupd)
{
lblUpdateErr.Text = "Error occurred in update";
}
}
}
Onclientclick is firing but not the onclick i.e. records are not updated. Is there a way to accomplish this?
Thanks Rashmi