make a component in a Repeater get enabled=false

Asked

Viewed 150 times

0

I have a button inside a Peater. As it is in a Peater, it only appears in the Databind() of the Peater. Using the variable and the event, I can get to that component like this:

protected void rptDocumentosRepeater_ItemDataBound(object source, RepeaterItemEventArgs e)
        {
            //Declarações
            try
            {
                //Instancias e Inicializações
                //Desenvolvimento
                if (....)
                {
                    e.Item.FindControl("fiuDocumentoUpload").
                }
            }
            catch
            { throw; }
        }

It turns out I need to give a Enabled=false and I can’t. In this command e.Item.FindControl("fiuDocumentoUpload"). I can’t bring Enabled. I can get Visible, but Enabled can’t. How I do?

His statement on Asp.Net

<td class="ajusteTdIe">
    <asp:FileUpload ID="fiuDocumentoUpload" runat="server" CssClass="acessos" />
</td>

2 answers

2


Have you tried casting for your component type?

var componente = (FileUpload)e.Item.FindControl("fiuDocumentoUpload");

if(componente != null)
    componente.Enabled = false;
  • I did as your example, but gives error of: Object not set for a instance of Object

  • Fileupload Ids do not change in Peater?

  • Do you refer to which ID’s? If it is the ID’s of the items yes, but only those. As for this: fiuDocumentUpload, then no.

0

Like the other friend said, you need to do a cast.
I tried to add as a comment on the reply but I still don’t have enough score for it (I’m new here).
I believe his cast Exception occurred at the time he passed another element on the list and tried to cast a cast. Use the cast with "as" that it will bring null if the cast is not possible, thus:

var componente = e.Item.FindControl("fiuDocumentoUpload") as FileUpload;
if(componente != null)
    componente.Enabled = false;

Or, check the object type before, like this:

var componente = e.Item.FindControl("fiuDocumentoUpload");
if (componente is FileUpload)
    ((FileUpload)componente).Enabled = false;

Browser other questions tagged

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