vb.net - 从 vb.net 中的 ID 字符串查找单选按钮控件

标签 vb.net user-controls session-variables

我的 aspx 中有 3 个单选按钮:

<asp:RadioButton ID="rdoMasculin" 
     runat="server" AutoPostBack="true" 
     Checked="true" GroupName="gender" 
     TextAlign="Right" />

<asp:RadioButton ID="rdoFeminin" 
     runat="server" AutoPostBack="true" 
     GroupName="gender" />

<asp:RadioButton ID="rdoAnonymous" 
     runat="server" AutoPostBack="true" 
     GroupName="gender" />

发送表单时,我将选中的单选按钮的 ID 存储在 session 变量中:

例如:Session("currentGender") = rdoZukuTermine.ID

当我稍后返回页面时,我在代码隐藏中使用以下代码:

Dim currentRadio = CType(FindControl(Session("currentGender")), RadioButton)
currentRadio.Checked = True
Session.Remove("currentGender")

currentRadio 最终成为空引用。但是当我检查 session 时,它包含正确的 ID 作为字符串。 有人可以帮助我吗?

最佳答案

RadioButton 控件是直接位于 .aspx 中还是有任何父控件?如果是,请在其直接父级上调用 Findcontrol(),如下所示:

Dim currentRadio = CType(ParentControl.FindControl(Session("currentGender")), RadioButton)

关于vb.net - 从 vb.net 中的 ID 字符串查找单选按钮控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40280442/

相关文章:

php - 如何从 session ID 获取值

php - 重定向到另一个域然后返回后丢失 session

c# - 如何找到我添加到表单中的重叠控件?

c# - 使用 C# 在设计器中隐藏调整大小标记?

c# - 动态用户控件在回发后获取并维护值

c# - 将值从页面传递到用户控件

c# - 使用Session验证用户名和密码

asp.net - 用户在ASP.NET应用程序中使用Entity Framework 4和VB.NET更新记录时设置值

asp.net - vb.net错误: inaccessible due to its protection level

MySQL/VB.NET - 使用了与请求的协议(protocol)不兼容的地址