Home Dashboard Directory Help
Search

WebPart Control stops creating/amending the ascx.g.cs File by JeffreyJa3


Status: 

Active


2
0
Sign in
to vote
Type: Bug
ID: 800844
Opened: 9/15/2013 8:39:20 PM
Access Restriction: Public
1
Workaround(s)
view
0
User(s) can reproduce this bug

Description

I have an issue building 2 webpart projects that have multiple UserControls.ascx for different users/reasons. For some reason the ascx.g.cs file is no longer automatically generating itself causing the error "The name 'InitializeControl' does not exist in the current context" along with other errors related to the ascx.g.cs file no being automatically populated. I have attached the projects so the error can be reproduced. I am using VS2012 with latest updates.
Details
Sign in to post a comment.
Posted by Hoots on 11/8/2013 at 7:47 AM
I also discovered that if the markup is wrong this will prevent the ascx.g file being generated. Can replicate this by adding two Width attributes to a Sharepoint:DVDropDownList.
Posted by Microsoft on 9/17/2013 at 5:25 AM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by Microsoft on 9/15/2013 at 8:51 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by JeffreyJa3 on 9/16/2013 at 9:49 PM
I have worked out why this was happening, it seems that if you nest .ascx UserControls in the main .ascx WebPartControl the ascx.g.cs file stops autogenerating, so this is using the "<%@ Register" tags and the adding the control to the page like below.

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DropboxWebPart.ascx.cs" Inherits="BGS.Dropbox.SP.DropboxWebPart.DropboxWebPart" %>

<%@ Register TagPrefix="DropboxForm" TagName="SubmitTeacher" Src="/_ControlTemplates/BGS.Dropbox.SP/SubmitTeacher.ascx" %>
<%@ Register TagPrefix="DropboxForm" TagName="SubmitStudent" Src="/_ControlTemplates/BGS.Dropbox.SP/SubmitStudent.ascx" %>

<div id="DropBoxContainer" class="DropBoxContainer" runat="server">
    <h2 id="FormHeader" runat="server"></h2>
    <div id="DropboxForm" class="StudentForm" runat="server">
        <DropboxForm:SubmitTeacher id="TeacherForm" runat="server"></DropboxForm:SubmitTeacher>
        <DropboxForm:SubmitStudent id="StudentForm" runat="server"></DropboxForm:SubmitStudent>
    </div>
</div>

Is this bad practice?

The workaround was to not register the UserControls but dynamically load the controls into the DropboxForm HtmlGenericControl above like so:

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DropboxWebPart.ascx.cs" Inherits="BGS.Dropbox.SP.DropboxWebPart.DropboxWebPart" %>

<style type="text/css">
    .yes
    {
        color: #347225;
    }
    .no
    {
        color: #a71a1a;
    }
</style>

<div id="DropBoxContainer" class="DropBoxContainer" runat="server">
        <h2 id="FormHeader" runat="server"></h2>
    <div id="DropboxForm" class="StudentForm" runat="server">
    </div>
</div>

and code side:

                if (syndb.isStaff(LoggedInUser))
                {
                    Control TeacherControl = Page.LoadControl("/_Layouts/ControlTemplates/BGS.Dropbox.SP/SubmitTeacher.ascx");
                    DropboxForm.Controls.Add(TeacherControl);
                }
                else if (syndb.isStudent(LoggedInUser))
                {
                    Control StudentControl = Page.LoadControl("/_Layouts/ControlTemplates/BGS.Dropbox.SP/SubmitStudent.ascx");
                    DropboxForm.Controls.Add(StudentControl);
                }

So the project now compiles and deploys, though I did prefer the other way to add the controls.
File Name Submitted By Submitted On File Size  
SolutionFingerprint.8440.html (restricted) 9/15/2013 -
UploadSummary-130916033920.xml (restricted) 9/15/2013 -
VsInfo.xml (restricted) 9/15/2013 -
SolutionFingerprint.6632.html (restricted) 9/15/2013 -
BG.PortalHotLinks.SP.zip (restricted) 9/15/2013 -
BGS.Dropbox.SP.zip (restricted) 9/15/2013 -
DxDiagOutput.txt (restricted) 9/15/2013 -