because the onClick method of a button control does not work?

0

I have a button that when pressing shows a modal and loads the data of a query but when pressing it does not react the method in the code of C # when doing tests it never enters the method.

<asp:Button ID="btnaddRequest" CssClass="btn btn-primary btn-lg" runat="server" data-toggle="modal" data-target="#MLrequest" Text="Agregar" OnClick="btnaddRequest_Click" />

in C #

protected void btnaddRequest_Click(object sender, EventArgs e)
{
        lblCprovidier.Text = "0";
        lblCproductos.Text = "0";
        lblCcot.Text = "0";
}
    
asked by Luis Alberto Acosta 09.02.2018 в 20:41
source

2 answers

0

This is the idea, first load the data in the labels in the onload event (or in the event that best suits you), and already with the data loaded in the DOM, you proceed to launch the modal with javascript or in the same button.

Control html prevents reloading the page.

<button href="#" id="btnTriggerModalEFNT" class="btn btn-primary btn-lg" data-toggle="modal" data-target="MLrequest">Agregar</button>

Loading data with c #

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            lblCprovidier.Text = "0";
            lblCproductos.Text = "0";
            lblCcot.Text = "0";
        }
    }

Do not forget to check the browser console to see if you have other problems such as not having loaded jquery or some syntax failure in javascript.

    
answered by 10.02.2018 в 00:06
0

This answer is to respond to your other case where you want to show the changes in a modal, as I said before you must load the data in the onload event and you must redirect to the same page when you finish your processes with the server control .

javascript

$(document).ready(function () {
$('#btnTriggerModalEFNT').modal('show');
});

with c #

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        lblCprovidier.Text = "0";
        lblCproductos.Text = "0";
        lblCcot.Text = "0";
        ListarRegistros(); // generas un procedimiento para listar tus registros
    }
}

        protected void btnaddRequest_Click(object sender, EventArgs e)
    {
        // Realizas todo tu proceso
        Response.Redirect("~/TuPagina.aspx");
    }
    
answered by 10.02.2018 в 00:29