I have used same command button Click event for both Insert, Update functionalities.
I’m checking with the url-querystring to achieve this functioality.
If the url-querystring is null then the page is meant for insert.
If the url-querystring is NOT null then the page is meant for update.
The code is shown below, but the update functionality is not working. When I debug the page, I understood that the new updated value is not presenting in the debug window. I have modified CR_TITLE and debugged. The new value is not coming in the debug. What is the problem?
protected void btnInsert_Click(object sender, EventArgs e)
{
try
{
ChangeRequest changeRequest = new ChangeRequest();
changeRequest.CR_REF_NO = txtCRRefNumber.Text.Trim();
changeRequest.CR_TITLE = txtCRTitle.Text.Trim();
changeRequest.ORIGIN1_ID = Convert.ToInt32(ddlOrigin1.SelectedValue);
if (Request["ecr"] == null)
{
(new ChangeRequestBLL()).InsertECR(changeRequest);
((BLMSite)this.Master).ErrorText = string.Empty;
((BLMSite)this.Master).MessageText = "Record inserted successfully";
}
else if (Request["ecr"] != null)
{
(new ChangeRequestBLL()).UpdateECR(ecrRefNo, changeRequest);
((BLMSite)this.Master).ErrorText = string.Empty;
((BLMSite)this.Master).MessageText = "Record updated successfully";
}
}
catch (Exception ex)
{
((BLMSite)this.Master).ErrorText = ex.Message;
((BLMSite)this.Master).MessageText = string.Empty;
}
}
Edit: I need to put this code inside (!Page.IsPostBack) condition. This is where I have committed mistake. Adding of this statement solved my problem.
It is just logic problem.
I handled the code just by setting iside !Page.IsPostBack condition and the problem is got solved. Hence, logic cannot be shown.
Thanks.