I am trying to cast a htmlinputtext to a htmlgenericcontrol
file.aspx :
<form runat="server" class="probootstrap-form">
<div class="form-group" style="margin-top: 20px">
<label for="name">Markt Name:</label>
<div class="form-field">
<input type="text" id="name" runat="server" required="required" class="form-control" />
</div>
</div>
</form>
file.aspx.cs :
HtmlGenericControl name = (HtmlGenericControl)Form.FindControl("name");
Error: System.InvalidCastException: Can't cast an object of the typ "System.Web.UI.HtmlControls.HtmlInputText" into "System.Web.UI.HtmlControls.HtmlGenericControl"
In the documentation you can see that
HtmlInputTextdoes not inherit fromHtmlGenericControland thus is not able to cast toHtmlGenericControlHtmlInputTextwould be able to cast toHtmlInputControl,HtmlControl,Controlorobjectof whichControlis the most generic that still makes sense in aspnet programming.