0

I am attempting to grab HTML elements in order to first set and then obtain the selected values for a radio list. I have the following elements

        <input type="radio" id="radioAlertOnly" name="AnomalyLevel" runat="server" value="0" />
        <input type="radio" id="radioIsolateAndAlert" name="AnomalyLevel" runat="server" value="1" />
        <input type="radio" id="radioRemediateAndAlert" name="AnomalyLevel" runat="server" value="2" />
        <input type="radio" id="radioRemediateAndLog" name="AnomalyLevel" runat="server" value="3" />

I have tried adding in the Blazor.WebForm.UI package that provides access to the System.Web.UI and System.Web.UI.HtmlElements libraries but neither of those has the FindControl method.

I also tried to just use a Panel but that made no difference.

Does anybody know how to access these elements in a code behind?

Yiyi You
  • 16,875
  • 1
  • 10
  • 22
Ken Tola
  • 93
  • 1
  • 1
  • 9
  • I followed the guidance found in this question - https://stackoverflow.com/questions/41395612/visual-studio-net-core-tag-helpers-not-working - but I am still not gaining the asp option when writing the control. – Ken Tola Nov 16 '21 at 17:54
  • I have added the_ViewImports.cshtml into my Pages folder where the main Razor page resides. I have in it an import to the Pages folder, the namespace pointing to my Assembly name and the main @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers And it still does not work. – Ken Tola Nov 16 '21 at 18:52
  • You appear to be confusing Razor Pages with Web Forms, which are incompatible technologies. System.Web is not supported in Razor Pages. Neither is the runat="server" attribute. Can you clarify exactly which type of application you are building? – Mike Brind Nov 16 '21 at 21:24
  • If you are using razor page,try to refer to the official [doc](https://learn.microsoft.com/en-us/aspnet/core/razor-pages/?view=aspnetcore-6.0&tabs=visual-studio) to know more about razor page. – Yiyi You Nov 17 '21 at 06:05
  • 1
    @KenTola there are no `HTML Controls` in ASP.NET since ASP.NET MVC 1.0, which was released in 2009. That's a WebForms concept that tried to make web sites behave like desktop apps and *wasn't used by any other framework* in the last 12 years. WebForms wasn't migrated to .NET Core because it's obsolete for a decade. – Panagiotis Kanavos Nov 17 '21 at 09:49
  • 1
    @KenTola you can't migrate a WebForms application to ASP.NET Core. You'll have to rewrite it. Razor Pages behaves *somewhat like* WebForms without the bad parts like server-side HTML controls. The middleware is completely different though - authentication, authorization, identity, data access are completely different. The generated HTML is completely different and orders of magnitude less. Browsers are different. An `input type='date'` behaves better than any DatePicker in WebForms did, without any JavaScript or server-side code – Panagiotis Kanavos Nov 17 '21 at 09:50
  • 1
    `Blazor.WebForm.UI package that provides access to the System.Web.UI ` no it doesn't. Blazor is a completely new technology using WebAssembly running on the client. What you used is a third-party package that emulates some of the old WebForms controls. It can't be used by itself, it's part of [this project](https://github.com/Jurioli/Blazor.WebForm.Components). It only works on a Blazor application. If you simply compare the example code with the `FetchData` generated when you create a new Blazor project, you'll understand why WebForms is dead – Panagiotis Kanavos Nov 17 '21 at 09:59
  • Thank you all for all of your help! I got rid on the runat-server components, re-wrote everything, and now I have one last challenge. I need to bind the options of an InputSelect to a dynamic datasource. In the documentation, it says that I should be using asp-items (https://www.learnrazorpages.com/razor-pages/forms/select-lists) but I STILL cannot get asp- to work. What am I missing? – Ken Tola Nov 17 '21 at 16:34
  • Ugh - I was being stupid. I kept using @asp-items="class.property" instead of asp-items="@class.property" – Ken Tola Nov 17 '21 at 16:40
  • @PanagiotisKanavos can you please elevate your comment to a solution so I can mark it as such and give you the proper credit? – Ken Tola Nov 17 '21 at 16:41

1 Answers1

0

@panagiotis-kanavos had a great answer in the comments above.

I also discovered that you can use either JavaScript calls or a simple @Ref call for HTML Elements or frontend components as shown in the links provided.

Ken Tola
  • 93
  • 1
  • 1
  • 9