Want to show message box using javascript

Hi everyone, I have a web form in which I have a button when I click on the data backup, I used the following javascript:

<script language="javascript" type="text/javascript"> function showPleaseWait() { document.getElementById('PleaseWait').style.display = 'block'; } </script> <asp:Button ID="btnTakebackup" runat="server" Text="Take Backup" Enabled="true" onMouseDown="showPleaseWait()" CausesValidation="false" /> <div id="PleaseWait" style="display: none;">"Please Wait Backup in Progress.."</div> 

Hi, I use the button for backup.

Now I want to show the message in the btnTakebackup_Click() event whether the backup was performed or not. I used Response.Write("<script>alert('abcd');</script>"); in the btnTakebackup_Click() event. But the problem is that I want to show the page also, which is not displayed, a white background is displayed instead.

Thanks in advance...

+4
source share
4 answers

To show a message with a message, you must write a new script stream to the response stream:

 var script = "<script type=\"javascript\">" + "alert(\"Backup in progress, don't go!\");" + "</script>" Response.Write(script); 

No matter how unpleasant it is, I believe that it is sometimes "necessary."

0
source

You can add client-side event handlers to ASP controls:

How to Add Client Script Events to ASP.NET Web Server Controls

Greetings.

0
source

From your question, I realized that after clicking on the button, the data is backed up, but the warning does not appear as soon as you press the button. This is because you are invoking JavaScript in a button click event that will only be run after all the code is executed when the button is clicked. I suggest you add the JavaScript function on the .aspx source page yourself and call the JavaScript function as shown below:

  <script ...> function xyz() { alert('Please Wait'); } </script> and in button declaration <asp:button id='btn_submit' runat="server" OnClientClick="return xyz();" /> 
0
source

Do you really want this to be a warning? (You should know that they block the entire browser, and not just the tab on which your page is located), do your users really need to confirm the success of the backup by clicking ok or just informing about it? ...

I suggest you have a div on the page that says "Backup successful". The visibility of which can be set using the logical property BackUpSuccess , which you can set to true in the code that you mention.

 <div id="backUpSuccess" <%=BackUpSuccess ? "" : "style='display:none;'"%>> Backup was successfull </div> 

... you can style the div as you like in your .css file to get attention.


If you really need an alert, you can run some JavaScript on the page load to check the contents of the hidden input that you installed on the server side in the same way ... but running javascript on the page load is complicated ... if only yours using jQuery, and then You will know it very easily.

0
source

All Articles