Deactivate asp.net mvc controls on the server side

2

Good morning, I present a small concern, recently I am working on a sales module for the company I work for. What I need is to deactivate two controls when identifying what is a cash sale:

Controls:

<input type="button" class="btn btn-primary" id="solici" onclick="parent.location='../Aspx/Visor/ConstruirReporte.aspx?Reporte=FAC2&id=<%=ViewData["id"]%>    '" value="Solicitud de crédito">

<input type="button" class="btn btn-success" id="aprobe" onclick="parent.location='../Aspx/Factura/DetalleAprobacion.aspx?id=<%=ViewData["id"]%>    '" value="Detalle Aprobacion">

I have tried with the following:

<% var factura = new MvcApp.Models.factura();

        var idFactura = Convert.ToDecimal(Request.QueryString["id"]);//recoge el parametro del registro
        var numerico = 2;//inicializo la variable en 2, equivale a una venta de contado

     if (factura.id_forma_pago == numerico)//valido
     {
         deshabilitarcontroles();//llamo al metodo 
     }}

   public void deshabilitarcontroles()
        {
            solici.Visible = false;//indicó funciones
            aprobe.Visible = false;
        }
     %>

My concern is that I do not recognize the id of each control, which instruction I must indicate to meet my objective.

- > Thank you in advance!

    
asked by Andrex_11 11.09.2018 в 17:21
source

2 answers

3

What you define are input from html and not web controls from asp.net, that is

<asp:Button

To access them from the server you must enter runat="server" then you will have html controls

HTML Input Controls

<input type="button" runat="server" class="btn btn-primary" id="solici" 

with which you could use

solici.Visible = false;

If it's a asp.net mvc project, you could hide the control using

<%if (factura.id_forma_pago != numerico){%>
    <input type="button" runat="server" class="btn btn-primary" id="solici" 
<%}%>

you condition the html so that the input is rendered or not

    
answered by 11.09.2018 / 19:41
source
2

It does not recognize them because they do not have the runat="server" property that allows you to access the controls from CodeBehind this means you can interact with their properties from On the server side, you can read a little about what I'm talking about.

In your case you can add the property to your input or use the Control Button asp like this:

<asp:Button ID="solici" runat="server" CssClass="btn btn-primary" Text="Solicitud de crédito" OnClick="parent.location='../Aspx/Visor/ConstruirReporte.aspx?Reporte=FAC2&id=<%=ViewData["id"]%>'" />
<asp:Button ID="aprobe" runat="server" CssClass="btn btn-success" Text="Detalle Aprobacion" OnClick="parent.location='../Aspx/Factura/DetalleAprobacion.aspx?id=<%=ViewData["id"]%>'" />

And in the CodeBehind :

public void deshabilitarcontroles()
{
   solici.Visible = false;
   aprobe.Visible = false;
}
    
answered by 11.09.2018 в 19:36