If a shortcut is required to display the message. Add a label on the page and set its visible = false attribute in aspx and use the following code:
protected void btnSubmit_Click(object sender, EventArgs e) { if(SaveRecordsToDataDatabase()) { If(UploadImage()) { showMessage("Save successfull",true); } else { showMessage("Save failed",false); } } else { showMessage("Save failed",false); } } private bool UploadImage() {
For consistency, you can use the transaction in the code above to prevent the save operation if the image upload failed. Otherwise, it is your choice. The new transaction code will be shown below:
protected void btnSubmit_Click(object sender, EventArgs e) { using(TransactionScope scope = new TransactionScope()) { if(SaveRecordsToDataDatabase()) { If(UploadImage()) { showMessage("Save successfull",true); } else { showMessage("Save failed",false); } } else { showMessage("Save failed",false); } } scope.complete() }
Here, to indicate the scope of the transaction, add the System.Transactions link.
Amit ranman
source share