最初禁用的按钮未呈现asp.net OnClientClick [英] asp.net OnClientClick not rendered for initially disabled Button

查看:76
本文介绍了最初禁用的按钮未呈现asp.net OnClientClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个禁用的asp.Button,稍后将使用JavaScript启用它.像这样

I have a disabled asp.Button, which I enable later with JavaScript. Like this

<asp:Button ID="btnSave" runat="server" Text="Save" Enabled="false" OnClientClick="; return ValidateFields();" OnClick="btnSave_Clicked" />

但是,禁用控件后,"onclick"方法不会呈现为html.我的解决方法是在PageLoad中添加以下代码.

However, the "onclick" method is not rendered as html when the control is disabled. My work around is to add the following code in PageLoad.

btnSave.Attributes["onclick"] = "return ValidateFields();";

为此有更方便的解决方法吗?

Is there a more convenient work around for this?

谢谢

推荐答案

您可以将html属性用于禁用

You can use the html attribute for disabled

<asp:Button disabled="disabled" ID="btnSave" runat="server" Text="Save" Enabled="false" OnClientClick="; return ValidateFields();" OnClick="btnSave_Clicked" />

我假设您随后在客户端启用了它?如果是这样,则可以使用:

I assume you then make it enabled in clientside? if so then you can enable it with :

document.getElementById('MainContent_btnSave').removeAttribute('disabled'); //or jquery alternative where MainContent_btnSave is the clientid of the control

这篇关于最初禁用的按钮未呈现asp.net OnClientClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆