<asp:Button ID="btnIdea" runat="server" Text="Publish Comment" AutoPostback="false"
OnClick="btnIdea_Click" BorderStyle="Double" ForeColor="#000000" />
Code behind
protected void btnIdea_Click(object sender, EventArgs e)
{
if (txtContent.Text == null)
Label7.Text = "Please select User Role";
else
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand insert = new SqlCommand("insert into dbo.Comments(Comment, UId, IssueDate, MaID, UserName) values(@Comment, @UId, @IssueDate, @MaID, @UserName)", conn);
int id = Int32.Parse(Request.QueryString["Id"]);
insert.Parameters.AddWithValue("@UId", Session["UniID"].ToString());
insert.Parameters.AddWithValue("@UserName", Session["Full_Name"].ToString());
insert.Parameters.AddWithValue("@MaID", id);
insert.Parameters.AddWithValue("@Comment", txtContent.Text);
insert.Parameters.AddWithValue("@IssueDate", DateTime.Now);
try
{
conn.Open();
insert.ExecuteNonQuery();
txtContent.Text = "";
// Response.Redirect("ACourseManagement.aspx");
}
catch
{
Label7.Visible = true;
Label7.Text = "Error when saving on database";
conn.Close();
}
}
}