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.    
ASP.NETWeb Development

Avatar of undefined
Last Comment
codingbeaver

8/22/2022 - Mon
Minh Võ Công

gery128

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.
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.
Your help has saved me hundreds of hours of internet surfing.
fblack61
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.
 
gery128

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.
Mare22

ASKER
gery128:

Once again, this is exactly what's missing.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
gery128

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
codingbeaver

Would mind sharing some of your code?