开发者

Controls in .aspx not visible in .aspx.cs, have you seen this before?

开发者 https://www.devze.com 2023-01-05 14:58 出处:网络
Have you ever experienced controls that are defined in the .aspx not being visible in the .aspx.cs? i.e. when you compile, it says your label or literal etc. has not been declared.

Have you ever experienced controls that are defined in the .aspx not being visible in the .aspx.cs? i.e. when you compile, it says your label or literal etc. has not been declared.

Is this a bug in vs.net?

Here is what I did, I created a new folder with the same file, and copied the .aspx content and codebehind, and then changed the references to the old file in the new file (like t开发者_高级运维he namespace, the codebehind reference in the aspx etc.)

I used beyond compare on both the .aspx and .aspx.cs to make sure I changed everything, yet when I compile I get like 25 errors.

This makes no sense to me, argh.

(using vs.net 2008)


I have seen this before but only with intellisense not picking it up. The compiler still recognized everything. Have you made sure to put runat="server" in your aspx page?


I'm not sure if this is your cause or not, but I have caused this to happen a couple of times, mainly by adding a server control while the site is running on my development server, and using custom controls.

As aspx.designer.cs files are read only while a site is running, the design code for the control can't be added.

My prefered solution is to just delete the designer file, right click the aspx file, and click "Convert to Web Application".


I have done this when I copied one to another and the .aspx tag

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MarkPage.aspx.cs"
    Inherits="Web.Apps.MyPrototype.MarkPage" %>

did not match my code behind:

namespace Web.Apps.FirstPrototype
{
    public partial class MarkOtherPage : System.Web.UI.Page


Can you check the designer file to see if the controls are defined there with their type? If not I use this technique to have it autogenerated again:

  • In source view cut the markup with the controls.
  • Go to Design view and there paste the copied markup.
  • Build the project again.

Normally that does the trick for me to regenerate the designer file and then in the codebehind you can use the controls.

Grz, Kris.


Change into design or split mode, make a small change (such as typing a space somewhere), and save. This will regenerate the missing designer.cs files


Do you have a folder in your project named the same as the file?


Are you sure that your name spaces are correct? Are you explicitly declaring the namespace in the .cs file?

Try removing the explicit namespace declarations.

Also, make sure that the partial class declaration is correct - and it would probably help if you posted some idea of what the error messages are, since there may be a clue in there.

Finally, I have seen occasions where a control gets messed up because of a conflict with some of the "special" names (Global, Local, etc) though I don't think I've seen this happen since VS2005.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号