ASP.NET hidden field vs. invisible textbox - asp.net

what are benefits of using a hidden field in ASP.NET when we can use another invisible element such as label or text box?

The hidden field generate <input type="hidden" /> element on the page, which cannot be seen but the client can get the element, set the data and pass to the server:
document.getElementById('<%= SomeHiddenField.ClientID %>').value = "data_pass_to_server";
after postback you can get the value:
var clientData = SomeHiddenField.Value; // "data_pass_to_server"
If you're using invisible textbox (<asp:TextBox Visible="False" />), there's no element generated in the html file.

Either way works, for text box, don't use .visible="false"
use
yourTextBox.Style.Add("display", "none")
or
yourTextBox.Style.Add("visibility", "hidden")

A hidden field renders as input type="hidden" in the resulting HTML. Being an input the value in the input is submitted to the server on postback while this is not the case with a label. Depending on whether or not you want that value submitted to the server you should use input or label. If you don't want the value to be submitted then label is the right solution and hidden field is wrong.
I am not sure what you mean by invisible textbox but if you are trying to make it invisible via CSS keep in mind that the input type has semantic meaning to search engines, bots, etc. Also at some point your HTML might be served without CSS or with different CSS and the text box will become visible to the user. Otherwise there are no differences between hidden field and invisible text box as both of them render inputs.

Practically you can achieve the same thing with any of them, but since you want a "hidden field", semantically speaking the hidden field in ASP.NET is your best bet for readability reasons.

Related

What is a valid alt text for an image only submit button?

I'm researching a website for accessibility issues and I found an image only submit input field for a search field.
Code of this input field is.
<input type="submit" value="Search">
I'm wondering if, giving this input field a value name 'Search' is sufficient to pass as an alternative text for succescriteria 1.1.1?
The value attribute provides the accessible name and visual label for a submit input, so the example should be sufficient.
If an actual image-input was used, the alt attribute must be used to provide an accessible name:
<input type="image" alt="Search" src="…">
Otherwise, it depends on the way the text is replaced with the image, as CSS can influence whether something is accessible or not. If the input element itself is still visible and focusable, it’s fine. If the whole element is hidden, especially from assistive technology, it’s not.
You can verify by inspecting the magnifying glass element in your browser, or by inspecting the accessibility properties. The name should be exposed.

Enable autocomplete feature in aurelia single page application

We have enabled autocomplete property true for all input fields. We didn't use form tags in the templates. The input fields don't fetch the previously entered data. So how can we implement autocomplete property.
Firstly, this is not specific to Aurelia. Once the element is in the DOM, it is a feature of the browser to offer the user a previously entered value for that field given that an assumption can be made about what the field is supposed to be!).
Depending on the browser, the autofill feature relies on having 'known' input attributes (name and type) and possibly even the surrounding text, including label text.
If you are not getting the expected results, try making sure your inputs have very obvious name attributes, first. Eg.
<input type="text" name="email">
If you could share a snippet of code, I might be able to offer more help.

Textbox with type="number" has blank Text

I'm working on the mobile version of my website and have a few textboxes where I want the virtual keyboard to popup as numbers (phone, zip, etc). Some of these also have custom filters attached to them to validate what's entered.
Because of the validators, I use asp:TextBox instead of a plain input. I then add type as an attribute in the codebehind
<asp:TextBox ID="SearchBox_Phone" runat="server" CssClass="inp-bl-lvl width95 l"
placeholder="Phone"></asp:TextBox>
SearchBox_Phone.Attributes.Add("type", "number");
I can get the correct value in js
$get('<%= this.SearchBox_Phone.ClientID %>').value;
but in the codebehind SearchBox_Phone.Text always returns blank. If I comment out the attribute addition I can get the correct value, but I really want to keep it as is.
Any idea how I can get the value, short of setting a hidden input in js (I'd like to avoid an extra value that needs setting/clearing)?

how does the hidden field keep its value on post back

Does any body have any idea how does the hidden field keep its value on post back when it is value is set from javascript and not from the server side code?
Can I create a text box that has this feature?
I worry I'm not understanding your question... but <input type="hidden" /> name/values get passed with a form like any other input, and you can certainly set their values with JavaScript, if you want. when you submit the form, it doesn't care - or even know - how the input fields got their values.

What is the easiest way to disable a form but keep it readable?

I have my form fields in a Panel which, if a read-only version is required, I set Enabled = False on the Panel. This was quick and dirty and the results are mostly dirty, mostly in IE. Can't scroll through large ListBoxes. Multi-line TextBoxes only show the first few lines. There's some funky styling to disabled Labels.
Do you have any ideas as to how to disable an entire form, letting the user read the data, visually indicating that it is disabled (gray input or text in place of input), but to the server keep the control disabled so it's not loading any data that could be manipulated by enabling fields by nefarious means.
(Also, I'm hoping I don't have to add a label corresponding to each data field.)
You could remove all the buttons and use jQuery to change the background color on all inputs. This would be a quick and easy solution.
$(':input').addClass('disabled');
You can have your fields assigned the readonly attribute, ie:
<input type="text" name=myText value="Enter Your Name" readonly>
This can easily be done with js but is more robust if done right in html.
You could also disable or even remove the submit button.
I would use the ASP web controls. The TextBox for the input type="text".
All web controls have the enabled property
<asp:TextBox id="txtSomething" runat="server" />
You can now enable/disable all controls from code like you do today (for the panel). But you have to do it for every one (I don´t know how many you have).
txtSomething.Enabled = False
You can also do this with JavaScript.
Loop all elements in the form, and disable/enable them.
function DisableEnableForm(myForm,setDisable){
elems = myForm.elements;
for(i=0;i<elems.length;i++){
elems[i].disabled = setDisable;
}
}
You can trigger this JavaScript function from ASP like this:
Button1.Attributes.Add("onclick", "javascript:DisableEnableForm(´form1´,true)");

Resources