Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I want to create Strongly typed Dynamic Text Boxes in MVC View. i have already create dynamic controls from Jquery but dont know how to make it strongly typed???


Please help me Guys...Thanks in advance.
Posted

1 solution

By definition, you cannot get anything like strong typing with JavaScript. It is based on a very different paradigm, loose typing, more exactly, dynamic and duck:
http://en.wikipedia.org/wiki/JavaScript[^],
http://en.wikipedia.org/wiki/Dynamic_typing[^],
http://en.wikipedia.org/wiki/Duck_typing[^].

As a matter of fact, there are only 9 distinct types in JavaScript, and only one of them is relevant to text boxes:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof[^].

You can create some pale imitation of strict typing if you compare the constructor objects of the objects.

For the detail on this idea, please see my past answers:
Is this code correct?[^],
WHy does this happen? Js[^],
which datatype is this[^].

In view of that, the "strongly typed text boxes" is something irrelevant. All you need is to enforce typing of some text box content by filtering out the characters typing. This is explained in detail here: http://www.javascripter.net/faq/keyboardinputfiltering.htm[^].

Another approach would be using some MaskedTextBox, or validation when the data is about to be used, or the combination.

If you want to take some "strict typing" route with JavaScript, first examine the sanity of your approach. Please read this: http://davidwalsh.name/javascript-objects-distractions[^].

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900