我正在尝试将htmlinputtext强制转换为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");错误: System.InvalidCastException:无法将类型为"System.Web.UI.HtmlControls.HtmlInputText“的对象强制转换为"System.Web.UI.HtmlControls.HtmlGenericControl”
发布于 2019-03-20 17:49:20
在documentation中,您可以看到HtmlInputText不是从HtmlGenericControl继承的,因此不能转换为HtmlGenericControl
HtmlInputText将能够转换为HtmlInputControl、HtmlControl、Control或object,其中Control是最通用的,在ASP.NET编程中仍然有意义。
https://stackoverflow.com/questions/55257696
复制相似问题