Link between aspx and aspx.cs

Niki Heaney 21 Reputation points
2022-11-11T20:19:07.677+00:00

So,
I changed the name of a control inside the aspx.cs file (not knowing at the time; that the name needed to match the id inside the aspx page)

once the deployment was compiled, I started seeing an object null exception..

Debugging the issue, I found the name needed to match - so, I changed the name of the control back and resubmitted a PR.

But, i'm still seeing the null object exception error......

My company doesnt replace the aspx file's if they havent been edited - and as the change was inside the aspx.cs they had no need to.
I've checked, and my change is 100% inside the deployed dll.....

And i know my code works - because we have a multi-version application and I had to duplicate my code inside the other version. (but, without the naming mistake and revert!)

the only thing, I can think of, is.... if there is a link between the aspx / aspx.cs pages that go beyond the id/control name - may be linked to a build or something?

if anyone has an idea of what the issue may be - I'd be grateful..

thanks,

my next step -
is to rename the control again, and this time rename the corresponding id inside the aspx (forcing my company to deploy by the aspx.cs and aspx pages together..)

Developer technologies ASP.NET Other
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 60,161 Reputation points
    2022-11-11T20:50:10.733+00:00

    There are 2 pieces of the control puzzle. On the server side codebehind (.aspx.cs) is the code you write. The corresponding .aspx file has controls marked with runat=server to indicate which controls need to have server side support. The name attribute (IIRC, id property otherwise) is the name that will be used on the client and server side. To hook the 2 pieces up the designer needs to generate a backing field that has the same name and type that the .aspx page is looking for. Therefore it generates the field in an .aspx.designer.cs file and creates it during construction of the form. If you aren't using a designer then the field would be defined and created inside the codebehind file.

    If you symbolically rename the field then it should rename in all places except maybe the .aspx page but you can simply fix the name attribute. If you renamed the control using the Properties window in the designer then it should fix up all references automatically.

    Honestly if it is horribly broken then I would consider going back to your original "bad" PR and compare what files changed. Those are the changes you need to undo. The commit history will have the value(s) that were used before your change so make sure you line them up.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.