Changing a linkbutton’s Text attribute inside a table in a Retpeater

Asked

Viewed 347 times

1

I have this linkbutton:

<td><asp:LinkButton ID="lkbEnviarDocumentos" CssClass="acessos" Text="Documentos" runat="server" /></td>} %>

When that condition is true if(hdfTipoUsuario.Value == "2") I have to change the Text of

Documents

for

Validate Documentos

How do I do that? I’ve tried it like this:

(LinkButton)e.Item.FindControl("lkbEnviarDocumentos").Text

but that way it doesn’t work. That way it doesn’t work. lkbEnviarDocumentos.Text = "Validar Documentos"; What’s the right way to do this? I tried on Asp.Net, putting an IF there, but he did not accept, he said that there are two equal ID’s, IE, not considered in the if or this or that, so.

<% if(hdfTipoUsuario.Value != "2"){%>
                        <td><asp:LinkButton ID="lkbEnviarDocumentos" CssClass="acessos" Text="Documentos" runat="server" /></td>} %>
                        <% } 
                        else
                        {%>
                        <td><asp:LinkButton ID="lkbEnviarDocumentos" CssClass="acessos" Text="Validar Documentos" runat="server" /></td>
                        <% } %>

I almost forget: All this is inside the itemcommand of repeater.

You know, I don’t think itemcommand is the place for that, right?

I did this Databound and now it’s wrong, saying: Object reference not set to an instance of an object.

protected void rptBens_ItemDataBound(object source, RepeaterItemEventArgs e)
        {
            //Declarações
            LinkButton vlkbDocumentos = null;

            //Instâncias e Inicializações
            vlkbDocumentos = (LinkButton)e.Item.FindControl("lkbEnviarDocumentos");

            //Desenvolvimento
            if (vlkbDocumentos.Text != string.Empty)
            { 
                if (hdfTipoUsuario.Value == "2")
                {
                    vlkbDocumentos.Text = "Validar Documentos";
                }
            }

        }

I was doing it wrong, but I fixed it. if now is like this and no more error:

if (vlkbDocumentos != null)
            { 
                if (hdfTipoUsuario.Value == "2")
                {
                    vlkbDocumentos.Text = "Validar Documentos";
                }
            }

It happens that even this way, the following is happening: The button comes repeated, one on top of the other. One with text Documentos and below that Validar Documentos, in the manner described above.

  • I think I should create an Itemdatabound event for Repeater and treat there, right? In the case of IF on Asp.net, the two buttons are pressed as it requires two buttons (different ID’s).

  • Even if I remove the linkbutton text from Asp.net, it still keeps going wrong. Somewhere it fills this linkbutton’s Text property.

1 answer

1

I solved the problem. Actually my IF is correct. Turns out it was inside a table, it broke the layout and, frankly, it looked like there were two buttons. As it was very tight, when inspecting, only marked the top. I only found out, when the colleague who is designer spoke, for me to increase the width of and that’s when I realized that it was just a button. Closed case.

Browser other questions tagged

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