Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

reading labels from an user control

3 views
Skip to first unread message

Hans

unread,
Jan 10, 2007, 7:14:26 AM1/10/07
to
Hello,

I have the following user control called encabezado (I cut some parts
of the code to make it shorter):

public partial class Encabezado : System.Web.UI.UserControl {
private String n;
public Encabezado()
{
//
// TODO: Add constructor logic here
//
}
public String estado
{
get
{
return lbl_estado.Text.ToString();
}
set
{
lbl_estado.Text = value;
}
}
public String numero
{
get
{
return n;
}
set
{
n = value;
}
}
private void page_load()
{
mostrar_encabezado(n);
}
private void mostrar_encabezado(String numero)
{

//Here I have a SQL Query and then:

lbl_nro.Text = Request.QueryString["reclamo"].ToString();
lbl_sucu.Text = dt.Rows[0]["nombre_sucu"].ToString();
lbl_titulo.Text = dt.Rows[0]["titulo_rec"].ToString();
lbl_usuario.Text = dt.Rows[0]["usuario_rec"].ToString();
lbl_asignado.Text = dt.Rows[0]["asignado_a_rec"].ToString();
lbl_estado.Text = dt.Rows[0]["estado_rec"].ToString();
lbl_icono_asig.Text = "";

// later use these to make a table, but it's not usefull for this
context.
}
}


To use the control I do:

<hparis:encabezado ID="encabezado1" runat="server" />

On the code:
encabezado1.numero = Request.QueryString["reclamo"];


And it works. Even the labels (lbl_estado.Text) are printed correctly
according to the specified number.
But when I try to use encabezado1.estado (i.e.:
Response.Write(encabezado1.estado)) I receive an empty String.
I only can access to encabezado1.numero, but no the others. Why is that
?

What am I doing wrong ?

greetings,

hans

marss

unread,
Jan 10, 2007, 8:30:40 AM1/10/07
to

Hans wrote:

> And it works. Even the labels (lbl_estado.Text) are printed correctly
> according to the specified number.
> But when I try to use encabezado1.estado (i.e.:
> Response.Write(encabezado1.estado)) I receive an empty String.

Hi,
It depends on the place where you want to use Response.Write. It is not
clearly stated so I make some supposition...
It can happen if you place one control (ChildControl.ascx) on another
control or page (ParentControl.ascx) and call a property of
ChildControl in the page load event handler of ParentControl. Because
page load event handler of ChildControl does not occur your property is
empty.

Hans

unread,
Jan 12, 2007, 6:17:20 AM1/12/07
to
Hello and thanks for your answer.

I use my user control on a page called "mostrar.aspx" and I put the
"Response.Write" on the same page. Any ideas ?

hans

marss

unread,
Jan 12, 2007, 7:37:42 AM1/12/07
to

Hans wrote:
> Hello and thanks for your answer.
>
> I use my user control on a page called "mostrar.aspx" and I put the
> "Response.Write" on the same page. Any ideas ?
>
> hans

Hello,
Where specifically on a page? If it happens in the Page_Load event
hadler then I discribed this situation above, if in another place - I
have no idea :(

Hans

unread,
Jan 12, 2007, 11:59:23 AM1/12/07
to
Hello,

This is what I do on the Page_load event of "mostrar.aspx.cs".

protected void Page_Load()
{
encabezado1.numero = Request.QueryString["reclamo"];

Response.Write("asignado: '" + encabezado1.asignado + "'");
//it prints an empty string
Response.Write("numero: "' + encabezado1.numero + "'");
//it prints the string I asigned above.

//some other code that isn't relevant.
}

Where should I put the 1st. response write ? Why numero is returned
correctly if it's also asigned on the Page_Load event ? I'm kinda new
to the .NET.

hans

marss

unread,
Jan 15, 2007, 2:33:07 AM1/15/07
to

Hans wrote:
> Hello,
>
> This is what I do on the Page_load event of "mostrar.aspx.cs".
>
> protected void Page_Load()
> {
> encabezado1.numero = Request.QueryString["reclamo"];
>
> Response.Write("asignado: '" + encabezado1.asignado + "'");
> //it prints an empty string
> Response.Write("numero: "' + encabezado1.numero + "'");
> //it prints the string I asigned above.
>
> //some other code that isn't relevant.
> }
>
> Where should I put the 1st. response write ? Why numero is returned
> correctly if it's also asigned on the Page_Load event ? I'm kinda new
> to the .NET.
>

Hi, Hans
Request pipeline:
1.Page load (Page, mostrar.aspx in your case).
2.Page load (Control, encabezado.ascx in your case).
3.Event handlers of controls placed on mostrar.aspx.

You are trying to access at step 1 to property that will be initilized
at step 2 only.
One of the solutions:
Rewrite some code in Encabezado:

....


public String numero
{
get
{
return n;
}
set
{
n = value;

mostrar_encabezado(n);
}
}
private void page_load()
{
}
....

0 new messages