vb.net 删除一行后,从代码隐藏中禁用 html 输入按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18208938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable html input button from codebehind, after deleting a row
提问by Purdy RA
I have an ASP.NET webpage that I enter a serial number in, and it then shows up in a gridview below.
我有一个 ASP.NET 网页,我在其中输入了一个序列号,然后它会显示在下面的网格视图中。
I can delete a row(serial#) if I change my mind. If there is zero rows in my grid I make grid disappear but I also want to make my submit button disappear as well.
如果我改变主意,我可以删除一行(序列号)。如果我的网格中有零行,我会让网格消失,但我也想让我的提交按钮消失。
How do I do that? Can I do it from: Sub Gridview1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs)
我怎么做?我可以从: Sub Gridview1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs)
If so, I've tried, but I can't seem to find the control to work with it.
Or is there any other way?
如果是这样,我已经尝试过,但我似乎无法找到使用它的控件。
或者还有其他方法吗?
HTML example:
HTML 示例:
<div style="width:800px; margin-right: 0px;" id="divMain" runat="server">
<table stuff...>
<input id="iSubmit" type="button" value="SubmitHere"/>
</table>
采纳答案by the_lotus
In the code behind you can show or hide the button
在后面的代码中,您可以显示或隐藏按钮
iSubmit.Visible = False
you have to make sure to add the runat="server" attribute
你必须确保添加 runat="server" 属性
<input id="iSubmit" type="button" value="SubmitHere" runat="server" />
So, when you delete a row, if the collection is empty then you can hide the button. When you add a new row, if the button if hidden then you show it.
因此,当您删除一行时,如果集合为空,则可以隐藏该按钮。添加新行时,如果按钮隐藏,则显示它。
回答by Satinder singh
HTML MarkUp:
HTML 标记:
You need to add runat="server"to your button so its ID can access from codebehind as the_lotus mentioned above
您需要添加runat="server"到您的按钮,以便其 ID 可以从代码隐藏访问,如上面提到的 the_lotus
<input id="iSubmit" type="button" value="SubmitHere" runat="server" />
CodeBehind:
代码隐藏:
1) iSubmit.Visible = false; // This will hide the button
2) iSubmit.Style.Add("display", "none");// This will hide the button
3) iSubmit.Enabled = false;//It disabled button, user can view but not able to click

