Assigning value to variable of type HiddenField is giving error

-1

I have this statement:

HiddenField vhdfCdTipoUsuario = null;

I have this assignment:

vhdfCdTipoUsuario = (HiddenField)e.Item.FindControl("hdfCdTipoUsuario");

If I do this, it gives this error:

if ((vhdfCdTipoUsuario.Value != Session["DsTipoUsuario"]) && (Session["DsTipoUsuario"] != null))
                    vhdfCdTipoUsuario.Value = Session["DsTipoUsuario"].ToString();

Object reference not set to an instance of an object.

How do I resolve this? The error gives here:

vhdfCdTipoUsuario.Value = Session["DsTipoUsuario"].ToString();

The Session is ok (populated). How do I work with variables of type HiddenField ? How do I assign value to this type of variable? I have already removed the ToString () from the Session and still tilt.

Here is the complete code:

protected void rptGerenciaProcessos_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            //Declarações
            HiddenField vhdfCdTipoUsuario = null;
            LinkButton vlkbPriorizar = null;
            string teste = "";

            try
            {
                //Instâncias e Inicializalções
                vhdfCdTipoUsuario = (HiddenField)e.Item.FindControl("hdfCdTipoUsuario");
                vlkbPriorizar = (LinkButton)e.Item.FindControl("lkbPriorizar");

                teste = Session["DsTipoUsuario"].ToString();

                if ((vhdfCdTipoUsuario != Session["DsTipoUsuario"]) && (Session["DsTipoUsuario"] != null))
                    vhdfCdTipoUsuario.Value = teste;

                //Desenvolvimento
                if (vhdfCdTipoUsuario != null)
                    if (int.Parse(vhdfCdTipoUsuario.Value) != 2 )
                        if (vlkbPriorizar != null)
                            vlkbPriorizar.Enabled = false;


            }
            catch (Exception Ex)
            {
                Mensagem = (wucMensagens)Page.Master.FindControl("wucMasterMensagens");
                Mensagem.ExibirMensagem(wucMensagens.TipoAlerta.Erro, Ex.Source, Ex.Message, Ex.StackTrace);
            }
        }
    
asked by anonymous 24.11.2014 / 14:49

1 answer

0

I started running and suddenly there was no exception. It continues the same thing, as in the first post:

if ((vhdfCdTipoUsuario != Session["DsTipoUsuario"]) && (Session["DsTipoUsuario"] != null))
                    vhdfCdTipoUsuario.Value = Session["DsTipoUsuario"].ToString(); 
    
24.11.2014 / 17:08