Reputation: 507
I have a textbox(it gets integer value) on my page and i set "0" to textboxes with this script at startup.
<script>
$(document).ready(function () {
$('.myclass').each(function () {
this.value = this.value || "0";
});
});
</script>
Also my textbox looks like:
@Html.TextBoxFor(model => model.Answers[i].Answer, new { @style = "width:45px; margin-left:10px; margin-bottom:10px; text-align:center;", @class="myclass" })
@Html.ValidationMessageFor(model => model.Answers[i].Answer)
How can i set null value after validation after postback? Because script set 0 value to textbox after every postback?
Thanks for help.
Upvotes: 0
Views: 51
Reputation: 10219
<script>
$(document).ready(function () {
$('.myclass').each(function () {
this.value = this.value || "";
});
});
</script>
If you use the script above it will empty the textbox. Which probably will not get the null
value, you want.
You should better disable it:
<script>
$(document).ready(function () {
$('.myclass').each(function () {
this.attr('disabled', true);
});
});
</script>
Upvotes: 1