ASP popup alert

I just started using ASP, so while c # programming code I was surprised to find out that the MessageBox is not available for me to make a confirmation popup on a button click. While googling I noticed a lot of suggestions for using Javascript but was hoping to avoid adding another language to my code. I tried to implement the suggested Javascript, but there must be something missing in the syntax.

I found the one that was all C #: C # MessageBox It compiles but doesn't issue warnings. I am still trying to figure out if I can get it to work. I called this the event on the button and thought that maybe this event was missed, but I also checked it on page load and still didn't pop up anything. Any suggestions?

+2


source to share


5 answers


You want to use javascript to validate your client side. I used to use ASP.net controls to do the same thing, but they are less flexible and cumbersome.

Declare a block in code to host the javascript function.

It's your

<script language="javascript"></script>

      

block.



To control your button, there must also be an onClientClick attribute that points to this javascript function, while the onClick attribute will still point to your C # function in code.

The xhtml button should look like this.

 <asp:Button ID="Button1" runat="server" OnClientClick="confirm_entry()" onclick="Button1_Click" Text="Button" />

      

Hope this is what you are looking for.

+2


source


You need to find out what's going on where. The C # code is run on the server and the result is sent to the browser. Select the view source in your browser to see what is being sent from the server.



To show the popup, you need to send a small piece of javascript to the browser, which will display the popup. However, it would be better to show the message box at the top of the page instead, as it is not intrusive.

+2


source


ASP is a server-side language. Anything you want to do client side must be either html / css, javascript (or any other client side, browser support, language).

+1


source


Attach an alert to the button's OnClientClick event. So myButton.OnClientClick = "alert ('message')"; If you want to call a user, for example, "Are you sure?" use a warning instead of confirmation:

myButton.OnClientClick = "return confirm (" are you sure? ")";

+1


source


You can use onclick = "retrun window.confirm ('Your message is here');

+1


source







All Articles