How do I access my .ascx attributes in my c # class?

0

I want to access one of my labels that I have in a .ascx file through a method that I have in my c # class. but I do not know how to do it.

How to implement .ascx in the aspx

<%@ Register Src="UserControls/EvidenceDetailLoad.ascx" TagPrefix="uc1" TagName="EvidenceDetailLoad" %>

Method of c #

    int idV=2;
    DateTime fechaC = DateTime.Now;
    DateTime fechaV = DateTime.Now;
    string QR= "4213546782145632";
    string FotoE = txtCode.Text;
    string status = "No autorizado";
    string dueno = "Lobo Beniton";
    int guardar = 0;
    string alumno = lblNombreAlumno.Text;  --- ERROR

The FotoE value takes it correctly but it is because its textbox is in the aspx and not in the .ascx, so what I want is to take the id's from the .ascx file that is in another location.

    
asked by David 12.05.2018 в 18:03
source

2 answers

1

For me the correct thing would be to expose lblNombreAluno.Text as a property of the user control.

Then in EvidenceDetailLoad.ascx you could have something like that.

public string NombreAlumno => lblNombreAluno.Text;

or

public string NombreAlumno
{
   get
   {
       return lblNombreAluno.Text;
   }
}

Depending on the version of C # you are using.

And then you consume that property:

string alumno = elNombreDelControlEnTuPagina.NombreAlumno;

I think it would be the "right" way to do it.

    
answered by 12.05.2018 в 21:54
0

You can use Page.FindControl ("Iddelcontro") as typecontorl;

example:

 string alumno = (Page.FindControl("lblNombreAluno") as Label).Text
    
answered by 12.05.2018 в 20:16