ASP.Net TextBox.AutoCompleteType property - useful? customizable? - asp.net

The ASP.Net TextBox control has an AutoCompleteType property that takes an AutoCompleteType enumeration value.
First, is this property commonly used in actual development? Or is "browser autocomplete" turned off and Ajax autocomplete used instead?
Second, are you constrained to only the values in the AutoCompleteType enum? Can you extend the AutoCompleteType enum to contain custom values?

The AutoCompleteType enum is merely a simple way of referencing the autocomplete expando attribute exposed by the html tag. This attribute can be any string, with "off" being reserved for disabling the feature. Any textboxes that use a specific string will start autocompleting from the same shared list of previous entries.
For example:
If you set autocomplete on 2 boxes to "car", the next time you visit a form with another box with autocomplete set to "car" your previously used choices will become available.

Setting autocompletetype="disabled" didn't actually turn off auto complete in Firefox. The only time autocompletetype works is when the client is using IE. (Yay asp.net browser sniffing.)
Using the non-standard attribute autocomplete="off" works -- and you can use this in your markup instead of using setattribute().

Related

What is a property and a control in Pega 7.2?

I want to know the difference between controls and properties in PEGA 7.2.
Property is like a variable in Java -
https://pdn.pega.com/sites/pdn.pega.com/files/help_v72/procomhelpmain.htm#rule-/rule-obj-/rule-obj-property/main.htm?Highlight=properties
Controls are used in pega to define how properties appear on UI -
https://pdn.pega.com/sites/pdn.pega.com/files/help_v72/procomhelpmain.htm#rule-/rule-html-/rule-html-property/main.htm
PDN is best source for all pega related definitions
Property is a Data field in general. You can imagine a variable in C or Java. That can be primitive type or complex type. In Pega, property type may be Single or Page, Page List, Object...etc.
Control is a UI component like textbox, button, checkbox, link...etc.
A property can be associated with a control to display in certain format on a user screen.
I would define a property 'CustomerName' and my control to read Customer name is 'TextBox'.
A property stores some value. It is like a box.
Control is a user interface element, which helps your system to get a value from or show it to a customer.
Always, properties and control are used together.
For example, a user fulfills a UI control with theirs name. And the name is assigned to some property.

ASP.NET long Name attribute - Why is there no ClientNameMode

In ASP.NET much has been made about the ClientIdMode property that gives developers greater control over the a control's ID attribute as it appears in the HTML.
However little attention appears to have be paid to the way the controls render their Name attribute. It appears to be a simple concatenation of the control's ID and its hierarchy of naming containers.
Given a sufficiently complex web page these names get very long. They not only make the HTML payload big (and ugly) but are also posted back to the server on every postback. (Also, they make their way into the Control State of some third party control suites. )
Why isn't there a ClientNameMode property - or similar? Surely it is as important as the Id attribute? Is it possible to override some method that generates / rehydrates the Name attribute so that we can man handle it to maybe match the Id? (made shorter by the ClientIdMode)
An example of a name of a control on a page that I am working on is
USoWAR1_tabContainer_UDetailsTabContainer_tabContainer_UDetailsTab_UDetails1_UDueDateAndNotifications1_decDetail_DataEntryRow1_datDueDate_DateTimePicker_calendar_AD
As far as I know the only way to alter this functionality is to extend controls into your own and override UniqueID property (e.g. by returning Server-side ID).
I had this same issue, and had to use JS to set the attr after loading.
$('#idofdomobjiwanttoname').attr("name", "whatIWantToNameIt");

How do I hide a checkbox label?

I have an ASP.NET checkbox and I'm using the .Text property to store a value. How do I hide the checkbox's text (label)? I'm using the .Text property for "hidden" storage of a single value.
Checkboxes aren't designed to store hidden values. Use a HiddenField instead.
When you use a hidden field, it's worth mentioning that the data will travel to the user along with the rest of the page. A more advanced user can modify this data then.
If you want to store a value between page loads and don't want the user to be able to modify it, you can use session state.
Use a custom attribute prefaced with "data-" to be HTML5 compliant.
<asp:CheckBox id="myCheckbox" data-ID='X' runat='server' />
EDIT:
You're probably wanting to do this from code-behind, though. Should be something like this (untested):
myCheckbox.InputAttributes.Add("data-ID", "X");

ASP.NET Checkboxes/RadioLists Arrow Keys

I have an ASP.NET web application for data entry, and we have big lists of radiobuttons, and long lists of checkboxes, in some sections.
The client wants to be able to be able to navigate and manipulate these controls with their keyboard, like the tab/space/enter/right-left-up-down-arrow-keys. Are there any ASP.NET controls that I can use?
You could use the TabIndex property and AccessKey properties of controls. The TabIndex will allow for in order navigation of controls using the Tab key. The AccessKey property can be used to set a specific keyboard letter to access the input field.
Using Jquery, you could use the .keypress() event to detect if the up/down key was press (See this for some hints). Then when used in conjunction with the TabIndex property, you could set focus to the next/previous input field.
This could be accomplished but it requires a bit of coding. You may have to add a keyup event to the body and handle the keys. I did the same for Jquery UI Tabs (right and left keys). You can use the concept to accomplish your stuff.
http://ctrlshiftb.wordpress.com/2010/02/03/how-to-add-keyboard-navigation-for-jquery-ui-tabs/
Hope this helps.
Thanks,
Raja
I may have misunderstood the question but if you set focus e.g.
RadioButtonList1.Focus();
keyboard shortcuts e.g. arrow-keys/space etc are available as standard behavior?
If you want more complex functionality you could add javascript attributes to you controls. This link is useful link text

Strange behavior using HTML 'readonly="readonly"' vs. JavaScript 'element.readOnly = true;'

Some background
So I was finishing up some enhancements in a web application that does some automatic interpolation of data. There are a handful of textboxes that the user fills out, and other textboxes in between them have values automatically calculated. The textboxes that receive automatically calculated values must be readOnly to prevent user changes, but can't be disabled or they won't get submitted on postback. Each of these textboxes also has a checkbox next to it so a user can consciously check it to make the field writable and thus allow them to override the interpolated value.
The browser: IE 7 (not sure how this behaves in others)
The issue
When setting the readOnly property of the textboxes with JavaScript, the value in the textbox is submitted with the form: I can see it on the server side (ASP.NET) with myTextBox.Text and it's in Request.Form("myTextBox").
If I set ReadOnly="true" on my <asp:TextBox /> element and don't use the JavaScript method, the value in the text box is NOT available from myTextBox.Text (I assume it never made it into the ViewState), but it is getting submitted with the form: Request.Form("myTextBox") has a value.
My question(s)
What the heck is going on? Is this by design? Is this a browser issue? Did I find a bug? It's annoying that I have to have some extra JavaScript to initially disable the writability of the textboxes when the page loads in order to make my app work.
Thanks!
This is by design. As an ASP.NET security feature, setting it to readonly on the server will keep it readonly regardless of what happens on the client. If you want them to be able override it and actually submit a value then it's not really readonly on the server, only conditionally on the client. You can either do a postback when they check the checkbox to change the readonly attribute on the server, or set only the readonly attribute on the client using this ASP.NET code:
MyControl.Attributes.Add("readOnly","readOnly")
Alright, I tweaked my sample and I think I see the problem - and I could be wrong, but I think it's behaving as intended.
When you set a field to be ReadOnly on the codebehind, the ASP:TextBox seems to become immutable even by JS. I made a change and the change was reflected in JS and in the form, but the TextBox retained its original text value -- unless I looked in the Request. Form as you did.
I don't think this is a bug. I think it's intentional, to keep something completely locked down - readonly on the server side hanging on does seem like a preferred choice.
May I suggest something using hidden input fields and spans or ASP:Labels (which effectively render as spans) to give a display aspect that isn't adjustable by the user?
Alternately, if you have access to a JS library (such as jQuery), you could set a CSS class on your TextBoxes (with CssClass="readonly" or something like that in your tag), then use the selection process to tweak the attribute, like so (assuming jQuery, easily written in other languages):
$("input.readonly").attr("readonly","readonly");
That way, you're not rewriting much of your markup and it's a quick'n'easy JS fix.

Resources