-1
I have this statement:
HiddenField vhdfCdTipoUsuario = null;
I have this assignment:
vhdfCdTipoUsuario = (HiddenField)e.Item.FindControl("hdfCdTipoUsuario");
If I do this, it makes that mistake:
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 fix it? The mistake is here:
vhdfCdTipoUsuario.Value = Session["DsTipoUsuario"].ToString();
Session is ok(populated). How I work with type variables HiddenField
?
How do I assign value to this type of variable? I’ve already removed Tostring() from Session and it still gives tilt.
Here is the full 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);
}
}
Have you tried to check if the assignment line actually assigns anything?
– Felipe Avelar
Yes, I want to exactly change that line, because it always brings an unexpected result. As there was a change in the scope, it is necessary to change this line: vhdfCdTipoUsuario = (Hiddenfield)e.item.Findcontrol("hdfCdTipoUsuario");
– pnet
But you assign before the if?
– Felipe Avelar
No, if is after assignment.
– pnet
Dude, your code looks okay. Plug it in, 'cause it could be a scope problem. Also, through a break point, see which of the objects is triggering the error, if the
vhdfCdTipoUsuario
orSession["DsTipoUsuario"]
.– lolol
Stack the Exception so it’s easier to help you.
– Renatto Machado
The error is in vhdfCdTipoUsuario, I’ve seen it. I’ll make an edit and post Too the code.
– pnet
That’s the Stack Trace I took. at Scania.SOMC.Web.frmGESStatusPriorizar.rptGerenciaProcessos_ItemDataBound(Object sender, RepeaterItemEventArgs e) in C:\Repositorio\ICSModuloCredito\Branches\ModuloCredito\ICS_MC\Scania.SOMC.Web\frmGESStatusPriorizar.aspx.cs:line 186
– pnet
Out of nowhere the mistake came back. That’s bone.
– pnet