Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@birojnayak
Copy link
Collaborator

This change will enable user control compilation/rendering etc inside the CoreWebForm . Fixing issue #19

Copy link
Collaborator

@twsouthwick twsouthwick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a unit test?

Just saw that you do already have those. let's just get the implementation cleaned up a bit

private async Task<T[]> GetDependencyPages(TemplateParser parser, CancellationToken token)
private static List<string> GetAllDependencies(string path)
{
var pageDependencyParser = new PageDependencyParser();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this implementation? Does overriding the virtual methods in the UserContorlParser not work?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you may want to override TemplateParser

    internal virtual IEnumerable<string> GetDependencyPaths()
    {
        foreach (var t in TagRegisterEntries)
        {
            yield return t.VirtualPath;
        }
    }

@twsouthwick
Copy link
Collaborator

can you add tests for the following (feel free to mark them as skipped if they aren't working yet):

  • A user control in another
  • A page that uses control A and B, where A depends on B

@twsouthwick
Copy link
Collaborator

So thinking a bit more about this, reminds me of getting masterpage to work. It initially required a type as well - I then changed it to a "TypeReference":

internal TypeReference MasterPage { get; private set; }

with an update here:

if (!typeof(MasterPage).IsAssignableFrom(type))
{
var path = VirtualPathProvider.CombineVirtualPathsInternal(this.CurrentVirtualPath, value);
MasterPage = new(Util.MakeFullTypeName("ASP", Util.MakeValidTypeNameFromString(path)), path);
//ProcessError(SR.GetString(SR.Invalid_master_base, value));
}

compare to referencesource: https://referencesource.microsoft.com/#System.Web/UI/PageParser.cs,534

It's unfortunate that WebForms "requires" the type to be available when just parsing - this change allowed that to be defered. Please see if you can do similarly.

@birojnayak
Copy link
Collaborator Author

So thinking a bit more about this, reminds me of getting masterpage to work. It initially required a type as well - I then changed it to a "TypeReference":

internal TypeReference MasterPage { get; private set; }

with an update here:

if (!typeof(MasterPage).IsAssignableFrom(type))
{
var path = VirtualPathProvider.CombineVirtualPathsInternal(this.CurrentVirtualPath, value);
MasterPage = new(Util.MakeFullTypeName("ASP", Util.MakeValidTypeNameFromString(path)), path);
//ProcessError(SR.GetString(SR.Invalid_master_base, value));
}

compare to referencesource: https://referencesource.microsoft.com/#System.Web/UI/PageParser.cs,534

It's unfortunate that WebForms "requires" the type to be available when just parsing - this change allowed that to be defered. Please see if you can do similarly.

I actually had looked at the code for Master page.. let me see if I can fit that model here..

@birojnayak
Copy link
Collaborator Author

So thinking a bit more about this, reminds me of getting masterpage to work. It initially required a type as well - I then changed it to a "TypeReference":

internal TypeReference MasterPage { get; private set; }

with an update here:

if (!typeof(MasterPage).IsAssignableFrom(type))
{
var path = VirtualPathProvider.CombineVirtualPathsInternal(this.CurrentVirtualPath, value);
MasterPage = new(Util.MakeFullTypeName("ASP", Util.MakeValidTypeNameFromString(path)), path);
//ProcessError(SR.GetString(SR.Invalid_master_base, value));
}

compare to referencesource: https://referencesource.microsoft.com/#System.Web/UI/PageParser.cs,534
It's unfortunate that WebForms "requires" the type to be available when just parsing - this change allowed that to be defered. Please see if you can do similarly.

I actually had looked at the code for Master page.. let me see if I can fit that model here..

Ok you could get by Master page because MasterPage are kept under asp:Content and asp:ContentPlaceHolder both are recognizable (Content and ContentPlaceHolder) asp controls, so there is an already pre-defined types. While usercontrol are dynamic control, so there is no defined types. You can look at https://referencesource.microsoft.com/#System.Web/UI/TagNameToTypeMapper.cs,501 why master page are fine.

Saying that, I think we need to build the dependency chain via sorting to build user control first, master page and web page.
Let me know if you think otherwise.

@twsouthwick
Copy link
Collaborator

twsouthwick commented Feb 29, 2024

Let's work incrementally here so we can make sure we're doing it right. I think the following is a progression we can work through to get things finished up:

  • PR to just add the tests (skipped for now)
  • Update TemplateParser to provide the virtual paths of dependent user controls and enable ascx in the PageCompilationOptions (maybe included with above as it's fairly trivial)
  • Enable sorting for the build (not convinced we need this, but have it as a separate thing)
  • Try to either (1) remove the compilation requirement or (2) enable a way to share the compilation result to the parser

Thoughts?

@birojnayak birojnayak force-pushed the User-control-latest branch from cd217ff to 6980ec0 Compare March 1, 2024 05:37
@birojnayak
Copy link
Collaborator Author

Created this PR to handle first 3, will create another PR to resolve the last one

Copy link
Collaborator

@twsouthwick twsouthwick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think (3) should be its own pr. I'm not convinced yet it's the way to do it - we can get (1) and (2) in first and then work through (3) and (4).

For example, it looks like we need to just use the DependencyParser class instead of the TemplateParser class to do the dependency identifcation. Can you get a TemplateParser from a DependencyParser? Should we have the compiler

(1) Create the dependency parser and identify order
(2) Create a TemplateParser (directly or via the DependencyParser) to do the parsing
(3) Get the generator and generate code

(2) and (3) of these steps are currently being done, but it looks like we may want to insert (1) before them.

@birojnayak birojnayak force-pushed the User-control-latest branch from 6980ec0 to ef5b3d5 Compare March 3, 2024 04:02
@birojnayak
Copy link
Collaborator Author

I think (3) should be its own pr. I'm not convinced yet it's the way to do it - we can get (1) and (2) in first and then work through (3) and (4).

For example, it looks like we need to just use the DependencyParser class instead of the TemplateParser class to do the dependency identifcation. Can you get a TemplateParser from a DependencyParser? Should we have the compiler

(1) Create the dependency parser and identify order (2) Create a TemplateParser (directly or via the DependencyParser) to do the parsing (3) Get the generator and generate code

(2) and (3) of these steps are currently being done, but it looks like we may want to insert (1) before them.

sorry for the confusion.. Should we have the compiler bit confusing.. what I assumed is, you probably want as much isolation as possible for compilation module to hold all logic related to compilation... check the newer revision, see how it looks and feel free to provide in-line comments, which will be helpful.

Copy link
Collaborator

@twsouthwick twsouthwick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll say again that it would be simpler to break this into smaller changes so we can have some parts of this done.

@twsouthwick
Copy link
Collaborator

Should we have the compiler bit confusing

Yeah, not sure what I meant there 😕

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestUserControl.ascx.cs" Inherits="SystemWebUISample.TestUserControl" %>
<%@ Register Src="~/InsideTestUserControl.ascx" TagPrefix="ucInside" TagName="InnerTestUserControl" %>

<div id="socialLoginList">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw can you simplify this control? we don't need it to do so much when all we want is a basic user control

@birojnayak birojnayak force-pushed the User-control-latest branch 2 times, most recently from 93ff271 to 61dd72d Compare March 7, 2024 07:35
@birojnayak birojnayak force-pushed the User-control-latest branch from 61dd72d to 9314cac Compare March 7, 2024 07:55
Copy link
Collaborator

@twsouthwick twsouthwick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking much better. A couple smaller things and then we're good to merge.

@birojnayak birojnayak force-pushed the User-control-latest branch from 0357fe5 to 536f2fa Compare March 8, 2024 03:10
Copy link
Collaborator

@twsouthwick twsouthwick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. There's a few issues we've created as follow up, but let's get this in so we have user controls

@twsouthwick twsouthwick merged commit 4f0ae7d into CoreWebForms:main Mar 8, 2024
@birojnayak
Copy link
Collaborator Author

LGTM. There's a few issues we've created as follow up, but let's get this in so we have user controls

Thank you.. lots of learning..

@birojnayak birojnayak deleted the User-control-latest branch March 5, 2025 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants