How to block asp c # button?

2

How can I block a form in .aspx ?

What happens is that when my button registers I can press again and can register twice as the image, that is, I want that when the warning comes out I only have the option to press accept.

This is my HTML:

<asp:Button ID="BtnnoConforme" runat="server" CssClass="btn btn-danger" style="font-weight:bold;margin-right: 5px;" Text="Registrar" OnClick="BtnnoConforme_Click" Font-Bold="True" />

This is my server code:

                         cmd.Parameters.Add("@fechacumplimientotarea", SqlDbType.Date);
                         cmd.Parameters.Add("@ERROR", SqlDbType.Char, 500);
                         cmd.Parameters["@fechacumplimientotarea"].Value = txtfechaoculta.Text;
                         cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output;


                         cn.Open();

                         cmd.ExecuteNonQuery();


                         message = (string)cmd.Parameters["@ERROR"].Value;


                         // lblErrorMsg.Text = message;

                         System.Windows.Forms.MessageBox.Show(message, "..::Aviso del Sistema::..");
                         BtnnoConforme.Enabled = false;
                         cn.Close();
                         Response.Redirect("FrmLogeo.aspx");
                         TxtMontoPagado.Text = "";
                         txtNumeroRecibo.Text = "";
                         TxtFecha.Text = "";
                     }

This is what my application shows:

    
asked by PieroDev 21.03.2017 в 21:14
source

4 answers

0

Friend, I give you an alternative to do it with javascript:

<asp:Button ID="BtnnoConforme" runat="server" CssClass="btn btn-danger" style="font-weight:bold;margin-right: 5px;" Text="Registrar" OnClick="BtnnoConforme_Click" Font-Bold="True" onclick="Desabilitar()" />

The javascript would be:

<script>

function Desabilitar() {
    document.getElementById("<%=BtnnoConforme.ClientID%>").enabled = false;
}
</script>

Greetings!

    
answered by 21.03.2017 / 21:54
source
0
BtnnoConforme.Enabled = false;

Put that code at the top, before executing the Query

    
answered by 21.03.2017 в 21:53
0

Maybe this can help you.

Add a style to css for example:

    <style>
        .hide {
            visibility: hidden;

        }

    </style>

and in the back add this style to the beginning of your method:

btnGuardar.CssClass = "hide";

The same and this can work for you.

I leave the example working.

link

    
answered by 21.03.2017 в 22:01
0

When you work with Web Pages of ASPX , try to not use Controls or features of WinForm , because surely they will not give you the correct operation.

With the code that you have at this moment, the message that you try to show the user is running on the server, what does that mean? Well, if a person tries to access the URL of your application at this time, for example: link and then press the register button, that person is not going to see the message, and this why? Well the messages will be appearing is on your PC (ie on the server) and not in the user's browser that I call the application.

This is one of the reasons why your page is not blocked, because the alert is not being launched by the browser (as it should be), but the alert is launching the web server process on its own system operative.

I could extend more explaining other implications that you have what you are doing, but I think the important thing now is to correct your application, which would be as follows:

First

Remove all references of your project that you have to System.Windows.Forms

Second

Fix your code as follows:

cmd.Parameters.Add("@fechacumplimientotarea", SqlDbType.Date);
cmd.Parameters.Add("@ERROR", SqlDbType.Char, 500);
cmd.Parameters["@fechacumplimientotarea"].Value = txtfechaoculta.Text;
cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output;


cn.Open();
cmd.ExecuteNonQuery();
message = (string)cmd.Parameters["@ERROR"].Value;
cn.Close();

// lblErrorMsg.Text = message;
//BtnnoConforme.Enabled = false;            

TxtMontoPagado.Text = "";
txtNumeroRecibo.Text = "";
TxtFecha.Text = "";

var scriptText = "alert('" + message + "'); location.href='http://tu-url-de-login';";
Page.ClientScript.RegisterClientScriptBlock(GetType(), "MessageScript", scriptText, true);
    
answered by 21.03.2017 в 22:23