Link to home
Start Free TrialLog in
Avatar of Mare22
Mare22

asked on

ASP.NET - getting control's ID from code behind

I have a bunch of controls (specifically, asp:ImageButton) being part of Gridview on .aspx page,
with runat="server" specified, of course.  I would expect them to be automatically included
in aspx.designer.cs file, and thus be accessible by id in .cs file, but they are not there.

How to make them be included on the server side and be accessible by id in .cs file?
Thank you.    
Avatar of Cong Minh Vo
Cong Minh Vo
Flag of Viet Nam image

are you copying ASPX markup from ASP.NET Website to ASP.NET Web-application?

Or you have added those controls to web-application on your own? If you have added them then it should be accessible in .cs file

check your aspx.designer.cs file for all controls' entries your are trying to accesss.
Avatar of Mare22
Mare22

ASKER

minhvc: thanks for your reply.  Your links contain a lot of useful information, and I tried some suggestions from there, like deleting and regenerating my aspx.designer.cs file and using FindControl, but I still can't get my controls.
Avatar of Mare22

ASKER

minhvc: what I am trying to say is that I did create the controls on my own and I checked my aspx.designer.cs file.  They are not there.  They are inside a gridview on aspx page.
 
in aspx.designer.cs file you should be able to locate auto generated code similar to like this:

 public partial class _Default {
        
        /// <summary>
        /// btn1 control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.Button btn1;
        
        /// <summary>
        /// btn control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.Button btn;
    }

Open in new window


If its not there then there is something wrong.
Avatar of Mare22

ASKER

gery128:

Once again, this is exactly what's missing.
ASKER CERTIFIED SOLUTION
Avatar of gery128
gery128
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Would mind sharing some of your code?