Difficulty to handle button event in the itemcommand of the Peater

Asked

Viewed 311 times

0

I have a table in a Repeater. In this table I have a Button and a Linkbutton. It turns out I need to pick up which click event was fired from the button or the linkbutton. I tried to make an if, but the button and linkbutton were incompatible. If I do this, I will always have the Text property on the button and 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);
            }
        }

At my Onclick Button event I have nothing. What I want is that when I click on 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 is a new task for me to do and as I get a click I something like this to say that the button clicked is one and not the other. The btnConsult part is what I’m trying to do.

2 answers

1

as I exemplified in the other post, just associate the event method to the button and link click.

See if the example below suits 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;
}

Methodos:

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

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

0

I did so:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.