C# 尝试访问asp.net中继器内的按钮 “class=“img”style=“宽度:300px;高度:300px;" /> 标题: 标题: 价格:英镑
如何控制aspx文件中的按钮,我想仅在创建会话时将按钮的可见性更改为true。您可以编辑按钮的C# 尝试访问asp.net中继器内的按钮 “class=“img”style=“宽度:300px;高度:300px;" /> 标题: 标题: 价格:英镑,c#,asp.net,C#,Asp.net,如何控制aspx文件中的按钮,我想仅在创建会话时将按钮的可见性更改为true。您可以编辑按钮的Visible属性: 数据绑定时直接执行(aspx或ItemDataBound事件中的代码隐藏) 由于您已经有了ItemDataBound事件,因此可以轻松检索事件中的addItem并将其设置为可见值 protected bool IsLogged() { return Session != null && Convert.ToBool(Session["IsLogged"]
Visible
属性:
ItemDataBound
事件中的代码隐藏)
由于您已经有了ItemDataBound事件,因此可以轻松检索事件中的addItem并将其设置为可见值
protected bool IsLogged()
{
return Session != null && Convert.ToBool(Session["IsLogged"]);
}
你能详细介绍一下“会话已创建”的含义吗?这可能会对回答产生重大影响。因此,当用户使用有效凭据登录时,会话已创建,我想使用该会话根据会话是否为空来切换按钮可见性。为什么不通过Viewbag发送并在视图中进行检查,就好像(ViewBag.IsAuthorized)asp.net web sense中的会话始终是创建的,无论用户是否经过身份验证。是否确实要检查用户是否已登录?@let__the_coding_begin,这不是asp.net mvc,没有ViewBag我是否将预渲染添加到中继器或按钮?如果要操作中继器中的单个行,则需要使用ItemDataBound事件。thanks这解决了我的错误,但我不得不在今天更改代码
<asp:Button ... Visible='<%# IsLogged() %>' />
protected bool IsLogged()
{
return Session != null && Convert.ToBool(Session["IsLogged"]);
}
protected void rptrProducts_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
var addItem = e.Item.FindControl("addItem") as Button;
addItem.Visible = Convert.ToBoolean(Session["SomeValue"]);
}
}