简体   繁体   English

你如何真正地向.aspx.designer.cs文件添加内容?

[英]How do you really add content to a .aspx.designer.cs file?

How do you really add content to a .aspx.designer.cs file? 你如何真正地向.aspx.designer.cs文件添加内容?

I have a stepPayment.aspx file, I have a stepPayment.aspx.cs file, and I have a stepPayment.aspx.designer.cs file. 我有一个stepPayment.aspx文件,我有一个stepPayment.aspx.cs文件,我有一个stepPayment.aspx.designer.cs文件。

The .aspx.designer.cs file has a warning at the top of the file that suggests that nothing in the file should be edited by hand: .aspx.designer.cs文件在文件顶部有一个警告,表示文件中的任何内容都不应该手动编辑:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated. 
// </auto-generated>
//------------------------------------------------------------------------------

Additionally, every variable in the file says it is it is an auto-generated field. 此外,文件中的每个变量都表示它是一个自动生成的字段。 Of course the designer field suggest I can add a new field in the code behind and this is what I have eventually done. 当然,设计师领域建议我可以在后面的代码中添加一个新字段,这就是我最终完成的工作。 Still, it would be good to know how to add content such that the auto-generated fields generate a new field that I want. 不过,知道如何添加内容以便自动生成的字段生成我想要的新字段会很好。

If you need to add info fast and secure in the designer file try this: 如果您需要在设计器文件中快速安全地添加信息,请尝试以下操作:

  1. Delete the the designer file from the page that you need fix. 从您需要修复的页面中删除设计器文件。
  2. Right Click on the aspx page file. 右键单击aspx页面文件。
  3. In the popup menu Click "Convert to web aplication". 在弹出菜单中单击“转换为Web应用程序”。

with that you'll regenerate the designer file again with all controls. 使用它,您将使用所有控件再次重新生成设计器文件。

I hope that helps. 我希望有所帮助。

Like Servy mentioned in the comments, you should never add anything to the designer explicitly. 像Servy在评论中提到的,你应该给设计师明确地添加任何东西。 Basically, just don't open it at all, as it is just a means to give you a way to manipulate the controls added to the page in the aspx (or ascx in case of user controls). 基本上,根本就不要打开它,因为它只是一种方法来为您提供一种方法来操作在aspx中添加到页面的控件(或者在用户控件的情况下为ascx)。

Every time you save the markup file, the designer is updated to contain the controls you added to it that have an explicit id set. 每次保存标记文件时,设计器都会更新为包含您添加到其中的具有显式ID设置的控件。 For other things that are not controls, you should create the fields/properties in the normal .cs file. 对于非控件的其他内容,您应该在普通的.cs文件中创建字段/属性。

Sometimes it's good to know that you can indeed recreate the designer completely, by following Freak_Droid's advice. 有时候通过遵循Freak_Droid的建议,确实可以完全重新创建设计师是件好事。 I've had to to that a few times because Visual Studio refused to update the designer file for some odd reasons. 我不得不这样做几次,因为Visual Studio因某些奇怪的原因拒绝更新设计器文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM