How to show the message "success" on submit?

Using C # with ASP.NET, how can I show a success message when my user submits a form? And at the same time, say โ€œImage was saved successfullyโ€ with a link so that the created image can be viewed by clicking the link?

+6
c # visual-studio-2010
source share
4 answers

Wrap your form in <asp:Panel> and create another <asp:Panel> with Visible="False" for your "Thank you" message. After submitting the form, change the visibility of each panel by setting the form to Visible="False" and the thank-you message panel to Visible="True" .

Hope that makes sense, here is an example:

 <asp:Panel ID="pnlFormFields" runat="server"> ... form fields here ... </asp:Panel> <asp:Panel ID="pnlThankYouMessage" runat="server" Visible="False"> ... Thank you message here ... </asp:Panel> 

Then inside your code

 protected void btnSubmit_Click(object sender, EventArgs e) { // Hook up uploaded image and assign link to it pnlFormFields.Visible = false; pnlThankYouMessage.Visible = true; } 
+6
source share

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() { // you upload image code.. } private bool SaveRecordsToDatabase() { // db save code } private void showMessage(string message, bool success) { lblMsg.visible = true; // here lblMsg is asp label control on your aspx page. lblMsg.FontBold = true; if(success) lblMsg.ForeColor = Color.Green; else lblMsg.ForeColor = Color.Green; lblMsg.Text = message; } 

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.

+2
source share

If you want to display a message on the client-side controls, for example alert ("saccess"); you can use ajax and webmethod in Why is my jQuery code not working in Firefox and Chrome? if you want to display the message on the server side, you can use the panel, label or div (the server runat and have id) and the default setting for them, set visiible false when you show the message, you can set the visible value true through the code behind.

0
source share

use the label (visible = false) and the hyperlink from the toolbar. When you upload an image, you must embed the url of the savefile into the database. When an insert query is run that returns an integer value that d there are no lines inserted in db.compare, as if this value is> 0, then set the visibility of the label to true and label.text = "success", finally set the navigation url of the hyperlink on the d url of the saved image, which can be used to create an image view link

0
source share

All Articles