wm-blazor-slick-carousel icon indicating copy to clipboard operation
wm-blazor-slick-carousel copied to clipboard

Unable to use OnInitializedAsync() with Blazor Server render-mode="Server"

Open Paul-Schroeder opened this issue 3 years ago • 1 comments

I could not figure out why my WMBSCInitialSettings were getting ignored and the BlazorSlickCarousel wasn't working. I tried so many things and believe that I isolated the problem down to a finding that you must use the OnInitialized() event. In other words, I could not use the OnInitializedAsync() method. Unfortunately, the data corresponding to the images I am trying to display get downloaded using an asynchronous data service that makes a call out to a Web API (I need the async).

It seems that by the time data is returned in the OnInitializedAsync() method, where I was calling the API, the BlazorSlickCarousel can't use it. Interestingly enough, the page will still display the data, but it does so as though the carousel component does not exist.

Sample code in a .razor page:

<BlazorSlickCarousel @ref="ArtistCarousel" Configurations="CarouselSettings" >
	<BlazorSlickCarouselContent>
		@foreach (var artist in Artists)
		{
			// divs and such go here to display the content
		}
	</BlazorSlickCarouselContent>
	<BlazorSlickCarouselLoading>
		<p>Loading...</p>
	</BlazorSlickCarouselLoading>
</BlazorSlickCarousel>

Then, in a code-behind / ViewModel (will not work):

protected override async Task OnInitializedAsync()
{
	Artists = await WebApiDataServiceWA.GetArtworksAsync(pageDataRequest));
}

Paul-Schroeder avatar Sep 21 '21 02:09 Paul-Schroeder