Alert Box in ASP.NET C #

0

I would like to ask if in ASP.NET C# you can do a alert similar to the one that can be done in Windows Form with the statement MessageBox . That if I press Si does something and if I press No it is canceled.

    
asked by PieroDev 22.06.2017 в 06:17
source

3 answers

1

For these cases it is best to program it on the client side with Javascript (as you are told).

As you talk about doing it in the codebehind I understand that you develop with Web Forms and that you would prefer to do it with some server control. You could use the ModalPopup from Ajax Control Toolkit . It's free and gives you the functionality you're looking for.

    
answered by 22.06.2017 в 07:57
0

You can add a OnClientClick to your button from the html and call the function:

OnClientClick="Aviso()" 

function Aviso()
{
    confirm("Press a button!");
}
    
answered by 22.06.2017 в 20:10
0

 <div class="modal fade" id="myModal">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">
                            <asp:Label ID="lblTitlePopUp" runat="server" Text="Label"></asp:Label>
                        </h4>
                    </div>
                    <div class="modal-body">
                        <div class="col-sm-4">
                            <img src="res/img1.png" width="174" />
                        </div>
                        <div class="col-sm-8">
                            <asp:Label ID="lblMessage" runat="server" />
                        </div>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">
                            Close</button>
                    </div>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
        </div>
        <!-- /.modal -->

        <button type="button" style="display: none;" id="btnShowPopup" class="btn btn-primary btn-lg"
            data-toggle="modal" data-target="#myModal">
            Launch demo modal
        </button>

        <script type="text/javascript">
            function ShowPopup() {
                $("#btnShowPopup").click();
            }
        </script>
c # code here
 if (code == true)//se inserto
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "alert", "ShowPopup();", true);
                        this.lblTitlePopUp.Text = "Muy bien";
                        this.lblMessage.Text = "Muy bien, ya te encuentras inscrito en nuestra base de datos ahora pueden iniciar sesión.";
                    }
                    else //problemas al insertar
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "alert", "ShowPopup();", true);
                        this.lblTitlePopUp.Text = "Algo salio mal";
                        this.lblMessage.Text = "Tu registro no ha podido llevarse a cabo debido a que estamos presentando errores en nuestros servidores. Te sugerimos volver a intentarlo más tarde.";
                    }

Create your controls so that you can execute them on the server side by adding the tag of runat="Server". and Inside the moodal you can place the controls you want.

    
answered by 30.08.2017 в 23:20