Empty Textbox value

If a textbox is empty it won’t add the value attributes in the html that’s rendered is there a way to make show like below?

<input name="Test" type="text" value="" id="Test" />

I have a javascript that checks the values of some textboxes but if it’s not renderer the it give me an error because it can’t find the attribute.

I forget what it’s called. I haven’t used WebForms for a few years now. I think it’s called “custom controls”.

Wouldn’t it just be better to fix the javascript to work with no value attribute if necessary?

I found some code that does it.


SetEmptyTextBox(this)

private void SetEmptyTextBox(Control Page)
    {
        foreach (Control ctrl in Page.Controls)
        {
            if (ctrl is TextBox)
            {
                if (string.IsNullOrEmpty(((TextBox)(ctrl)).Text))
                {
                    TextBox txt = ((TextBox)(ctrl));
                    txt.Attributes.Add("value", "");
                }
            }
            else
            {
                if (ctrl.Controls.Count > 0)
                {
                    SetEmptyTextBox(ctrl);
                }
            }
        }
    }