我的网络表单中有一个javascript函数,如下所示:
<asp:Button ID="btnRemoveNodeAssets" runat="server" OnClientClick="return deleteNodeAssets();"
Text="Remove Item" OnClick="btnRemoveNodeAssets_Click" />
点击“删除”按钮
时会触发deleteNodeAssets()
我面临的问题是,即使true
返回btnRemoveNodeAssets_Click
,我的代码隐藏方法class SMS {
public string GetPort() {
if (ErrorCondition) {
throw new PortNotFoundException("Error finding port.");
}
return port;
}
public void ExecuteCommand(Command command) {
if(ErrorCondition1) {
throw new UnknownErrorException("Error Executing Command");
}
else(ErrorCondition2) {
throw new NoResponseException("No Response from device");
}
}
public void SendMessage(int number, string text) {
FindPort();
ExecuteCommand(command);
}
}
根本不会触发。
答案 0 :(得分:0)
Asp.net按钮不是提交类型按钮。
生成后按钮将为<input type="button" />
如果您的方法在OnClientClick
中返回值,则onClick
将不会触发。
因此,如果您的方法返回false,则返回值
如果reutrn为false则不执行任何操作,然后onClick将被调用
试试这个
OnClientClick="if(!deleteNodeAssets()) return false;"