0

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.

1 Answer 1

1
<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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.