0

I have some controls on a page and i am not able to access the controls in code behind, it is coming in scientific intelligence. I am getting the cause of that.

here is my HTML code of web control:

   <%@ Control Language="c#" AutoEventWireup="false" Inherits="DNNInfo.Modules.Classifieds.Controls.CompanyClassifiedList" %>
   <div id="divDetailsDownloadFile" runat="server" class="DNNInfo_ClassifiedDownloads" visible="false">
      <asp:LinkButton ID="linkDownloadFile" Text="Download File" runat="server" />
    </div>

i am talking about the linkbutton here.

here is code behind code:

namespace DNNInfo.Modules.Classifieds.Controls
{
   public class CompanyClassifiedList : PortalModuleBase
    { override protected void OnInit(EventArgs e)
    {
        InitializeComponent();
        base.OnInit(e);
    }

    private void InitializeComponent()
    {

        try
        {
            this.Load += new System.EventHandler(this.Page_Load);
           LinkButton linkDownload_File = (LinkButton)this.FindControl("linkDownloadFile");

            if (linkDownload_File != null)
            {
                linkDownload_File.Click += new EventHandler(this.linkDownloadFile_Click);
            }

        }
        catch (Exception ex)
        {

        }
    }
  }
}

It always return null in "linkDownload_File". i am not able to recognize the error. what is the cause for this behavior.

any help will be appreciated.

UPDATE: i have checked by made div visible.. but still its returning null

Ram Singh
  • 6,664
  • 35
  • 100
  • 166

2 Answers2

1

You need to look for it recursively, because it is within DIV. As an alternate way of doing this is to use Page.FindControl this way:

http://blog.codinghorror.com/recursive-pagefindcontrol/

but perhaps more recommended way:

Better way to find control in ASP.NET

or try to remove runat="server" on DIV

Community
  • 1
  • 1
Robert
  • 3,276
  • 1
  • 17
  • 26
0

did you try the below:-

LinkButton linkDownload_File = (LinkButton)divDetailsDownloadFile.FindControl("linkDownloadFile");