如何从 asp HiddenField 获取和设置值
我想向 HiddenField
ASP.NET 控制器添加一个布尔值,以便在回发后可以保留该值。这是我的代码:
Public Property IsAddingNewCause() As Boolean
Get
Return IsAddingNewCauseField.value
End Get
Set(ByVal value As Boolean)
IsAddingNewCauseField.value = value
'^^^^^^^^^^^^^^^^^^^^^this is where I want to set the HiddenField's value!
End Set
End Property
ASP.NET Markup
<asp:ListView ID="lstNewCause" runat="server" DataSource="..." >
<EditItemTemplate>
<tr>
<td>
<asp:HiddenField ID="IsAddingNewCauseField" runat="server" Value="" />
[...]
编辑
问题是找不到控件的 ID: 错误 311 名称“IsAddingNewCauseField”未声明。
I want to add a Boolean value to a HiddenField
ASP.NET controller so that the value can be retained after postback. Here is my code:
Public Property IsAddingNewCause() As Boolean
Get
Return IsAddingNewCauseField.value
End Get
Set(ByVal value As Boolean)
IsAddingNewCauseField.value = value
'^^^^^^^^^^^^^^^^^^^^^this is where I want to set the HiddenField's value!
End Set
End Property
ASP.NET Markup
<asp:ListView ID="lstNewCause" runat="server" DataSource="..." >
<EditItemTemplate>
<tr>
<td>
<asp:HiddenField ID="IsAddingNewCauseField" runat="server" Value="" />
[...]
EDIT
The problem is that the control's ID is not being found:Error 311 Name 'IsAddingNewCauseField' is not declared.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您需要在列表视图控件中搜索它。该控件没有设计器条目,仅在动态创建时才存在。我可能是错的,因为我在手机上无法检查。
编辑包含的代码,它将遵循这些原则。
I reckons you need to search the listviews controls for it. The control doesn't get a designer entry and only exists when created dynamically. I might be wrong as I'm on my phone and can't check.
Edit included code, its going to be along these lines.
HiddenField 值属性类型为 String。您必须在 get 中将 IsAddingNewCauseField.Value 转换为 Boolean,并在 set 访问器中调用 value.ToString()。
HiddenField value property type is String. You must convert IsAddingNewCauseField.Value to Boolean in the get and call value.ToString() in the set accessor.