Difficulty to handle button event in repeater itemcommand

0

I have a table in a repeater. In this table I have a Button and a LinkButton. It turns out that I need to pick which click event was fired from the button or from the linkbutton. I tried to do an if, but failed to be incompatible the button and the linkbutton. If I do this, I will always have the Text property of the button and the if will never work: var btnConsultar = (Button)e.Item.FindControl("btnConsultarProcessos");

This is my ItemCommand

protected void rptGerenciaProcessos_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            //Declarações
            HiddenField vhdfCdProcesso = null;
            HiddenField vhdfCdAnalise = null;
            HiddenField vhdfCdUsuario = null;

            try
            {
                //Instâncias e Inicializalções
                vhdfCdProcesso = (HiddenField)e.Item.FindControl("hdfCdProcesso");
                vhdfCdAnalise = (HiddenField)e.Item.FindControl("hdfCdAnalise");
                vhdfCdUsuario = (HiddenField)e.Item.FindControl("hdfCdUsuario");

                var btnConsultar = (Button)e.Item.FindControl("btnConsultarProcessos");

                //Desenvolvimento 


                if (vhdfCdProcesso != null)
                    hdfCdProcessoPriozar.Value = vhdfCdProcesso.Value;
                else
                    hdfCdProcessoPriozar.Value = string.Empty;

                if (vhdfCdAnalise != null)
                    if (vhdfCdAnalise.Value != string.Empty)
                        hdfCdAnalisePriorizar.Value = vhdfCdAnalise.Value;
                    else
                        hdfCdAnalisePriorizar.Value = string.Empty;
                else
                    hdfCdAnalisePriorizar.Value = string.Empty;

                if (vhdfCdUsuario != null)
                    if (vhdfCdUsuario.Value != string.Empty)
                        listaUsuariosDropDownList.SelectedValue = vhdfCdUsuario.Value;

                pnlPriorizar.Visible = true;




            }
            catch (Exception Ex)
            {
                Mensagem = (wucMensagens)Page.Master.FindControl("wucMasterMensagens");
                Mensagem.ExibirMensagem(wucMensagens.TipoAlerta.Erro, Ex.Source, Ex.Message, Ex.StackTrace);
            }
        }

In my OnClick event of the button I have nothing. What I want is that when I click the button it does something and when I click on the linkbutton it does something else. The linkbutton is working. The button is that it's a new task for me to do and as I get a click pou something to say that the button clicked is one and not the other. The part of btnConsulting is what I'm trying to do.

    
asked by anonymous 18.11.2014 / 13:35

2 answers

1

As I exemplified in the other #

See if the example below caters to you:

protected void rptGerenciaProcessos_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    // Procurando controles no Repeater
    var button = (Button)e.Item.FindControl("btnConsultarProcessos");
    var link = (LinkButton)e.Item.FindControl("lnkConsultarProcessos");

    // Associando eventos.
    button.Click += btnConsultarProcessos_Click;
    link.Click += lnkEnviar_Click;
}

Method:

// Button
protected void btnConsultarProcessos_Click(object sender, EventArgs e)
{
    // Faça algo ...
}

// Linkbutton
protected void lnkEnviar_Click(object sender, EventArgs e)
{
    // Faça algo ...
}
    
18.11.2014 / 17:05
0

I did so:

Type vintTipo = e.CommandSource.GetType();
if (vintTipo == typeof(Button))
{
   //Aqui faço coisas
}
else
{
   //Aqui faço outras coisas
}
    
18.11.2014 / 17:11