简体   繁体   中英

designer.cs issues with using user control in Visual Studio

During my development, I have a web user control project and another web project which will use the user controls from the web user control project.

So I copy the DocControl.ascx file to my web project and try to use the properties of the DocControl.ascx. But VS does not know the properties of the control. So when I check the designer.cs, the reference is like that

protected global::System.Web.UI.UserControl Control;

Which should be

protected global::MSN.DocControl Control;

So I changed the name of the control from System.Web.UI.UserControl to MSN.DocControl and I can use the properties of the DocControl.ascx.

But my issue is whenever I modify ( eg. put a lable in aspx) the aspx file, the reference in designer.cs become

protected global::System.Web.UI.UserControl Control;

So I has to change it whenever I modify my aspx.

What should I do so I don't need to change the designer.cs

Thanks in advance......

I have solved it by moving

protected global::MSN.DocControl Control;

from designer.cs to .cs page.

So whenever you made any changes, it will be OK.

@kokbira - > hope that it helps you.

In my case, it was a bad src path in my register line. This caused no error messages, but would generate the generic control instead of the specific class, with the same symptoms you describe.

I had this (which has the wrong Src path):

<%@ Register TagPrefix="uc" TagName="Pipes" Src="/Controls/Pipes.ascx" %>
...
<uc:Pipes id="ucPipes" runat="server" />

and it generated this, which is generic, and has none of the control's properties:

protected global::System.Web.UI.UserControl ucPipes;

When I did the correct path, with Category folder, it worked:

<%@ Register TagPrefix="uc" TagName="Pipes" Src="/Category/Controls/Pipes.ascx" %>
...
<uc:Pipes id="ucPipes" runat="server" />

and generated this correct one, so all properties worked:

 protected global::Company.Category.Controls.Pipes ucPipes;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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