Search code examples
c#htmlasp.net-corerazor-pages.net-6.0

Accessing Html Controls In Code Behind on c# Razor 6.0 Page


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?


Solution

  • @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.