locked
Code Behind (ASPX.CS) is not able to access the (.ASPX) elements. RRS feed

  • Question

  • User1915385617 posted

    I get the error message "The name does not exist in the current context". However when I run the code on my local IIS server the website executes perfectly even though Visual Studios thinks my .CS file can't see an element in the ASPX file such as a ListBox, or a Label. Visual Studios won't detect this and I have to write all the functions manually.

    Normally it would detect my elements from the designer, and I would be able to type listBox1.... and all the methods and properties would popup.

    WebOrder.aspx.cs https://pastebin.com/raw/tfKtWH2L

    WebOrder.aspx https://pastebin.com/raw/S3NuE37K 

    Sunday, November 18, 2018 3:50 PM

All replies

  • User1120430333 posted

    "The name does not exist in the current context".

    Well it should be helpful if you showed some code. Maybe, the ASPX is not referencing the code behind class correctly.

    Sunday, November 18, 2018 6:08 PM
  • User1915385617 posted

    Sorry should have thought of that haha

    WebOrder.aspx.cs https://pastebin.com/raw/tfKtWH2L

    WebOrder.aspx https://pastebin.com/raw/S3NuE37K 

    Sunday, November 18, 2018 6:14 PM
  • User1120430333 posted

    Showing the code would also show what element is code is giving the error.

    Sunday, November 18, 2018 9:23 PM
  • User1915385617 posted

    Pastebin link is in original post now. And this happens for every element. Thanks

    Sunday, November 18, 2018 9:25 PM
  • User-893317190 posted

    Hi Stefon,

    In you pasted link, I only find two controls that you have used in your code behind,  h1title and RadGrid1. 

    You say this happens to all your elements.

    It seems that there is something wrong in your visual studio ,are you sure your visual studio work well?

    Have you compile your project before you run your project ?

    If you  don't compile your project, the code you actually run will be different from the code you write.

    This means even your code is wrong, the aspx may still run well, but this doesn't mean there is nothing wrong with your code.

    Anyway, please rebuild your project before you run your project and then see what error message shows, if it shows nothing wrong then start your project

    Best regards,

    Ackerly Xu

    Wednesday, November 21, 2018 6:19 AM