C
C#10mo ago
jacks

blazor service issues

i'm trying to set a variable based on data inside of my service but it's not letting me do it unless it's inside of a method
No description
16 Replies
jacks
jacksOP10mo ago
and currently i can't call upon the method without getting errors so i'm not sure what to do
xyrile
xyrile10mo ago
why not put it on protected overried async Task OnInitializedAsync? to set the variable
Jimmacle
Jimmacle10mo ago
without knowing what the errors actually are we can't suggest much
jacks
jacksOP10mo ago
i'm unfamiliar
jacks
jacksOP10mo ago
No description
Jimmacle
Jimmacle10mo ago
there you go, you can't do that
jacks
jacksOP10mo ago
but how can i work around this
Jimmacle
Jimmacle10mo ago
do it in a method like xyrile suggested
jacks
jacksOP10mo ago
how would i do that in the way that he said to
Jimmacle
Jimmacle10mo ago
override that method and put your code in it
jacks
jacksOP10mo ago
yea but in this page? and how would i call the method?
jacks
jacksOP10mo ago
i tried calling the method like this
No description
jacks
jacksOP10mo ago
top one doesn't work bottom one is just error
Anu6is
Anu6is10mo ago
They said override on initialized It's called automatically when the component initialises You don't have to call it yourself, add the logic in there Just type override and space and the available methods should show
jacks
jacksOP10mo ago
okay i got it thank you
xyrile
xyrile10mo ago
Since you are unfamiliar with some of the life cycle of a razor you can check this out https://learn.microsoft.com/en-us/aspnet/core/blazor/components/lifecycle?view=aspnetcore-8.0
ASP.NET Core Razor component lifecycle
Learn about the ASP.NET Core Razor component lifecycle and how to use lifecycle events.
Want results from more Discord servers?
Add your server