Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASP.NET Web Forms (VB.NET) config #963

Closed
pmonty opened this issue Nov 1, 2019 · 7 comments
Closed

ASP.NET Web Forms (VB.NET) config #963

pmonty opened this issue Nov 1, 2019 · 7 comments

Comments

@pmonty
Copy link

pmonty commented Nov 1, 2019

Wondering if it is a possibility to get this done. We have an existing ASP.NET Web forms app we would love to convert to ReactJS and really want to use this package.

Just a test I installed the nuget React.Web.MVC4 package and it added a reactconfig.cs to App_Start. Is there a way to generate vb files or do i need to convert them manually? Fine to do the entire thing manually. But thought I would ask here if this is even possible before I went and started adding stuff for no reason maybe?

@dustinsoftware
Copy link
Member

dustinsoftware commented Nov 1, 2019 via email

@Daniel15
Copy link
Member

Daniel15 commented Nov 1, 2019

It's not tightly-coupled to MVC so it should work with WebForms too. You might find this issue useful: #55

I don't have any VB examples, but anything doable in C# should be doable in VB too 😄

@pmonty
Copy link
Author

pmonty commented Nov 1, 2019

Thanks for the quick reply guys!

After some messing about I have the following:
App_Start/ReactConfig.vb

Imports React
<Assembly: WebActivatorEx.PreApplicationStartMethod(GetType(ReactConfig), "Configure")>
    Public Module ReactConfig
        Sub Configure()
            ReactSiteConfiguration.Configuration.AddScript("~/Scripts/React/index.jsx")
        End Sub
    End Module

test.aspx

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
    <div>
        hello this is div test
    </div>
  <asp:Literal ID="PageContent" runat="server"></asp:Literal>
</asp:Content>

test.aspx.vb

            Dim env = AssemblyRegistration.Container.Resolve(Of IReactEnvironment)()
            Dim objectModel = New With {Key .user = "React User"}
            Dim reactComponent = env.CreateComponent("PageContent", objectModel)
            PageContent.Text = reactComponent.RenderHtml()

It is rendering the div but not my react component

UPDATE:
Realised I missed the ReactConfig.Configure() line in my global.asax file. Added it but still get the same error. My page loads the master page and for some reason it shows a 500 error. Really strange. If i comment out the test.aspx.vb code then it renders the div again but no the react component.

UPDATE 2:
Now messing around in a test webforms project I setup. I get the following on line
Dim env = AssemblyRegistration.Container.Resolve(Of IReactEnvironment)()
image

Have also tried ReactEnvironment.Current per your tip in #55

@pmonty
Copy link
Author

pmonty commented Nov 1, 2019

Have just setup a repo so it is easier to see what I have done... wrong 😄 ReactJS.WebForms repo

Edit was reading and discovered I might need to add Microsoft.ClearScript, so done it and then also removed those from /bin via web.config and still get the same issue.

Update:
Despite what is in #409 I found another thread where @Taritsyn mentioned not to install Microsoft.ClearScript if you have V8 already. So I then went through the React.Sample.Mvc4 project and saw both x86 and x64 packages of JavaScriptEngineSwitcher.V8.Native.win were installed so added the missing one and now I am getting Error while loading "~/Scripts/React/index.jsx": TypeError: React.createClass is not a function... so a little closer :) will push up the changes to the example repo

@pmonty
Copy link
Author

pmonty commented Nov 5, 2019

Ok so got it working. Main issue was I think forgetting env.GetInitJavascript() and calling ReactConfig.Configure() in global.asax.vb

Seems it wasn't necessary to call that explicitly.

Will close for now as it seems it is all working. Going to attempt webpack bundling and typescript support. If that all works can actually attempt copying some react stuff into our project and working inside which will significantly help!

Amazing effort by all collaborators and contributors! Great project

@sushmitasen11
Copy link

@pmonty how did you resolve this issue mentioned in #Update2, however i am working in asp.net and getting the same error for the line :
_env = AssemblyRegistration.Container.Resolve(); which is written in 500.aspx page.

@omartheman
Copy link

omartheman commented Jan 30, 2024

@pmonty Did you ever happen to make a video or something showing the whole process? I've tried to do this multiple times using other resources, but have never succeeded. Maybe one day I can get around to trying your above steps.

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

No branches or pull requests

5 participants