基于asp.net中文本框中的文本的Javascript启用/禁用按钮 [英] Javascript enable/disable button based on text in textboxes in asp.net

查看:69
本文介绍了基于asp.net中文本框中的文本的Javascript启用/禁用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写这个



< script language =javascripttype =text / javascript>

//功能如果两个文本框包含文本,则启用按钮

函数SetButtonStatus(发送者,目标){

var first = document.getElementById('<%= txtfirst.ClientID%> ');

var second = document.getElementById('<%= txtText.ClientID%>');

//检查用户是否输入文本的条件是否两个文本框

if((sender.value.length> = 1&& first.value.length> = 1)&&(sender.value.length> = 1&& second.value.length> = 1))

document.getElementById(target).disabled = false;

else

document.getElementById(target).disabled = true;

}

< / script>









i write this

<script language="javascript" type="text/javascript">
//function to enable button if two textboxes contains text
function SetButtonStatus(sender, target) {
var first = document.getElementById('<%=txtfirst.ClientID %>');
var second = document.getElementById('<%=txtText.ClientID %>');
//Condition to check whether user enters text in two textboxes or not
if ((sender.value.length >= 1 && first.value.length >= 1) && (sender.value.length >= 1 && second.value.length >= 1))
document.getElementById(target).disabled = false;
else
document.getElementById(target).disabled = true;
}
</script>




<div>
<asp:TextBox ID="txtfirst" runat="server" onkeyup="SetButtonStatus(this,'btnButton')"></asp:TextBox>
<asp:TextBox ID="txtText" runat="server" onkeyup="SetButtonStatus(this,'btnButton')"></asp:TextBox>
<asp:Button ID="btnButton" runat="server" Text="Button" Enabled="false" />
</div>

< br $>








但它会抛出错误



错误是:








but its throws an error

the error is:

The Controls collection cannot be modified because the control contains code blocks 





我的尝试:



JavaScript启用/禁用基于asp.net中文本框中文本的按钮



What I have tried:

JavaScript Enable/disable Button based on text in textboxes in asp.net

推荐答案

此问题完全控制渲染问题。



如果脚本文件/ javascript代码块存在于Web表单,母版页或内容页面的头部,从页面的标题部分删除JavaScript并将其添加到正文部分的底部。然后清除浏览器缓存并运行您的应用程序。







将代码块替换为<% #而不是<%=



希望这可以解决您的问题。
This issue is completely control rendering problem.

If script files/javascript code block is present in head section of web form, master page or in content page, remove JavaScript from the header section of page and add it bottom of body section. Then clear the browser cache and run your application.

or

Replace the codeblock with <%# instead of <%=

Hope this will resolve your problem.


这篇关于基于asp.net中文本框中的文本的Javascript启用/禁用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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