首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从ASP.NET onclick中隐藏图像按钮

从ASP.NET onclick中隐藏图像按钮
EN

Stack Overflow用户
提问于 2016-11-29 01:02:39
回答 3查看 1.3K关注 0票数 0

我正在尝试隐藏/显示ASP.NET模板中的编辑/保存按钮。因此,我希望编辑按钮在未选中任何行时显示,然后在单击时将其隐藏,然后使保存按钮可见。

如何访问和更新属性?

我尝试过的解决方案只给出了"Null"

我所拥有的:

代码语言:javascript
复制
<ItemTemplate>
     <asp:ImageButton ID="ImageButtonEdit" runat="server" CommandName="Edit" ImageUrl="loginstyling/images/Edit.png"/>
     <asp:ImageButton ID="ImageButtonUpdate" runat="server" CommandName="Update" ImageUrl="loginstyling/images/Save.png" OnClick="ImageButtonUpdate_Click" Visible="true"/>
     <asp:ImageButton ID="ImageButtonDelete" runat="server" CommandName="Delete" ImageUrl="loginstyling/images/Remove.png" visible="false" />
</ItemTemplate>

我在后面尝试过:

代码语言:javascript
复制
protected void ImageButtonUpdate_Click(object sender, ImageClickEventArgs e)
{
    ImageButton test = (ImageButton)GridView1.FindControl("ImageButtonUpdate");
    test.Attributes.Add("Visible", "False");

}
EN

回答 3

Stack Overflow用户

发布于 2016-11-29 01:12:24

如果此方法有效,请尝试:

代码语言:javascript
复制
    test.Visible = false;
票数 0
EN

Stack Overflow用户

发布于 2016-11-29 01:20:49

您确定.FindControl("ImageButtonUpdate");返回一个有效的对象吗?

由于它在另一个post FindControl() return null中返回null检查,这似乎与您遇到的问题相同。

票数 0
EN

Stack Overflow用户

发布于 2016-11-29 01:37:34

尝试为GridView使用RowDataBoundEvent,如果它有效的话:

代码语言:javascript
复制
protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow)
    {
        ImageButton test = (ImageButton)e.Row.FindControl("ImageButtonUpdate");
        test.Visible = false;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40849700

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档