I want to disable Asp.net textbox on the client side using javascript if it's not empty.
I am using the following function for empty check and to disable the textbox.
<script>
function check(textBox) {
if (textBox.innerText = (field.value === "")) {
textBox.disabled = true;
}
}
</script>
and the following code which I used in pageload
ASPxTextBox1.Attributes.Add("onchange", "check(this);");
and following is my aspx.
<dx:ASPxTextBox ID="ASPxTextBox1" runat="server" Height="35px" Width="44px">
<ClientSideEvents TextChanged="function check(textBox)" />
</dx:ASPxTextBox>
It's not working for me. I don't know what's the problem.
Is there any way to achieve the same.
Note: I am using DevExpress ASPxTextBox controls.
The whole function looks like as below.
<script type="text/javascript">
function OnTextChangedHandler(s) {
alert('TextChanged. Text = ' + s.GetText());
s.SetEnabled(false);
}
</script>
Your html is as bellow.
<dx:ASPxTextBox ID="ASPxTextBox1" ClientInstanceName="txtReceiver" runat="server" Height="35px" Width="44px">
<ClientSideEvents
TextChanged="function(s, e) {
OnTextChangedHandler(s);
}" />
</dx:ASPxTextBox>
Since this is a ASPxTextBox
according to their documentation s.SetEnabled(false);
this code can be used to disable the control. s.GetText()
can be used to get the text value from the control. For more info check this link .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.