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……

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

Method 2

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;


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x