How to validate while typing in textbox using mvc3 - asp.net-mvc-3

In my page I am Having 5 TextBoxes and 1 DropDownlist box
Name (It should allow only alphabets)
UserName (It should allow both alphabets and numeric)
EmailID (Email format)
PhoneNo (Only Integers
Gender
Password (Combination of alphates and numeric)
The above things should validate in while typing itself and If the format is correct tick image should display.....
If we press tab without entering data error message should display below the TextBox
Please kindly help me...
I am fresher and new to mvc3..
Below is the code i have created. Now I need to validate.... please tell me how to do it
<table>
<tr>
<td> #Html.Label("FirstdName")</td>
<td> #Html.TextBox("FirstName")</td>
<td> #Html.ValidationMessageFor(x => x.FirstName)</td>
</tr>
<tr>
<td> #Html.Label("Username")</td>
<td> #Html.TextBox("Username")</td>
<td> #Html.ValidationMessageFor(x => x.Username)</td>
</tr>
<tr>
<td> #Html.Label("Password")</td>
<td> #Html.TextBox("Password")</td>
<td> #Html.ValidationMessageFor(x => x.Password)</td>
</tr>
<tr>
<td> #Html.Label("ConfirmPassword")</td>
<td> #Html.TextBox("ConfirmPassword")</td>
<td> #Html.ValidationMessageFor(x => x.ConfirmPassword)</td>
</tr>
<tr>
<td> #Html.Label("Phone")</td>
<td> #Html.TextBox("Phone")</td>
<td> #Html.ValidationMessageFor(x => x.Phone)</td>
</tr>
<tr>
<td> #Html.Label("Gender")</td>
<td> #Html.DropDownListFor(Per => Per.Gender, new[]{
new SelectListItem(){Text="Male",Value="Male"},
new SelectListItem(){Text="Female",Value="Female"},
}, "--Select--")</td>
<td> #Html.ValidationMessageFor(x => x.Gender)</td>
</tr>
<tr>
<td> #Html.Label("Email")</td>
<td> #Html.TextBox("Email")</td>
<td> #Html.ValidationMessageFor(x => x.Email)</td>
</tr>
</table>
<input type="submit" value="Ok" />
</form>

Validation in MVC 3 is based on Annotations or Attributes which the model we are binding with the view . Check this out and u will know.
As you put the Validation Attributes , they are handled on the client side with the help of unobstrusive javascript. And it handles the way it should be handled automatically. Adding custom logic could be done with the help of jquery (like showing tick marks and messages alternately).
Raj , in here you wont get ready code snippets made for you when you havent tried yet.
So this is a General piece of advice . Come up with the issues you are facing and you will get the help from the awesome fraternity of yours. And off track Welcome to Tech world dude !

Related

When I add a link to a table cell another table is created

I created a website using TYPO3 version 10.4.21. TYPO3 uses the CKEditor as rich text editor.
On one page I need to display many links because it's a summary of archive documents. For that I created a table inside the RTE, each cell contains the doc-name.
The problem is when I create a link on the doc-name it will automatically create another table inside the cell around the text. As my tables are styled it will mess up the whole design. How can I disable that?
I can confirm as NextThursday said that the error only occurs if there is only one word in the cell or if I select the whole cell.
<table>
<tbody>
<tr>
<td>
<table>
<tbody>
<tr>
<td>Doc1</td>
</tr>
</tbody>
</table>
</td>
<td>Doc2</td>
<td>Doc3</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
These are the only configurations I made to the CKEditor:
imports:
- { resource: "EXT:rte_ckeditor/Configuration/RTE/Default.yaml" }
- { resource: "EXT:rte_ckeditor_image/Configuration/RTE/Plugin.yaml" }
editor:
externalPlugins:
indent:
resource: "EXT:layout/Resources/Public/RTE/Plugins/indent/plugin.js"
indentblock:
resource: "EXT:layout/Resources/Public/RTE/Plugins/indentblock/plugin.js"
config:
externalPlugins:
- indent
- indentblock
removePlugins: null
processing:
allowAttributes: [class, id, title, dir, lang, xml:lang, itemscope, itemtype, itemprop, style]

post a combination value instead of many drop-down values

i am working on a project where a clerk like professional will make/edit classes time table for educational institute.
so in a day-period cell there are many drop-downs for selecting teacher, classroom/lab, batch of students, subject etc.
and this whole combination of values can be repeated many places in the grid.
so i want to post a single value combining all these 4-5 values through POST data in FORM for that cell location.
what approach should i use?
EDIT:
Oh! Yes, i am actually using PHP and angularjs and this is sample code in html
<table border="1" width="90%" height="90%" style="margin:10px">
<thead>
<tr>
<td>
Day
</td>
<td ng-repeat="hour in chours">
{{hour.name}}
<br>
{{hour.stime}}--{{hour.etime}}
<br>
<input type="checkbox" ng-model="hour.noclass" /> No class {{hour.noclass}}
</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="day in weekdays">
<td>
{{day.name}}
</td>
<td ng-repeat="hour in day.hours">
<div ng-show="hour.noclass=='false'" name="cell[{{day.name}}][{{hour.name}}][]">
<select name="cars">
<option ng-model="dd" ng-repeat="sub in subjects">{{sub.name}}</option>
</select>
{{dd}}
</div>
</td>
</tr>
</tbody>
<tfoot></tfoot>
</table>
and this is in js file
var App = angular.module('tteditApp',[]);
App.controller('editCtrl', function($scope){
$scope.chours=[
{'name':'1','stime':'800','etime':'855','noclass':'true'},
{'name':'2','stime':'855','etime':'950','noclass':'true'},
{'name':'3','stime':'800','etime':'855','noclass':'false'},
{'name':'4','stime':'800','etime':'855','noclass':'false'},
{'name':'5','stime':'800','etime':'855','noclass':'false'},
{'name':'6','stime':'800','etime':'855','noclass':'false'},
{'name':'7','stime':'800','etime':'855','noclass':'false'},
{'name':'8','stime':'800','etime':'855','noclass':'false'},
{'name':'9','stime':'800','etime':'855','noclass':'false'},
{'name':'10','stime':'800','etime':'855','noclass':'false'}];
$scope.subjects=[{'name':'CLOUD'},{'name':'CC'},{'name':'ISS'},{'name':'DCT'},{'name':'DMW'},{'name':'VLSI'},{'name':'SEMINAR'},{'name':'PROJECT'},{'name':'WEB DEV'}];
$scope.weekdays=[{'name':'Monday','hours':$scope.chours},{'name':'Tuesday','hours':$scope.chours},
{'name':'Wednesday','hours':$scope.chours},{'name':'Thursday','hours':$scope.chours},{'name':'Friday','hours':$scope.chours}
,{'name':'Saturday','hours':$scope.chours}];
});

xpath: how select radio button of particular item if html is equal and order could be changed

How can I click on radio button using xpath in selenium if I have following html:
<tr>
<td>
<input type="radio" onclick="onSelect(this.form)" value="met" name="selected_item"/>
</td>
<td> Val1</td>
<td> 1</td>
<tr>
<td>
<input type="radio" onclick="onSelect(this.form)" value="met" name="selecteditem"/>
</td>
<td> Val2</td>
<td> 1</td>
SOLUTION
Finally I have found decision:
.//tr[td[contains(., 'Val1')]]/td[1]/input
//td[text()=' Val1']/preceding-sibling::td/input
or
//td[text()=' Val2']/preceding-sibling::td/input

big table makes internet explorer 8 freeze

I have a simple ASP.NET MVC3 index page which holds more than 11k items. I have buttons for operation links as an extra. The code is like follows:
<table class="list">
<tr>
<th></th>
<th>
Name
</th>
<th>
Code
</th>
<th>
Explanation
</th>
</tr>
#foreach (var item in Model) {
<tr>
<td>
<a href="#Url.Action("Edit", new { id = item.ID })" class="noUL">
<img class="opr" src="#Url.Content("~/Content/Images/edit.png")" alt="Edit" title="Edit" />
</a>
<a href="#Url.Action("Details", new { id = item.ID })" class="noUL">
<img class="opr" src="#Url.Content("~/Content/Images/info.png")" alt="Details" title="Details"/>
</a>
<a href="#Url.Action("Delete", new { id = item.ID })" class="noUL">
<img class="opr" src="#Url.Content("~/Content/Images/delete.png")" alt="Delete" title="Delete"/>
</a>
</td>
<td width="600px">
#Html.DisplayFor(modelItem => item.Name)
</td>
<td>
#Html.DisplayFor(modelItem => item.Code)
</td>
<td>
#Html.DisplayFor(modelItem => item.Explanation)
</td>
</tr>
}
There's no problem opening it with any other browsers inluding Chrome and Firefox, but in IE8 first it tries running, then locks permanently. I don't expect a good performance from IE, but how can I make it work? Small tips for just saving the day are greatly appreciated. I tried to give static width to a varying sized column, for example.
UPDATE: I deleted the image links' column and it worked; even faster with tables, rather than div-ul-li setup I tried before.
I recommend you if you have bulk data, override the paging on the table. Send your data to table part by part with JSON. In every next or prev buttons clicking send new list to table.

Why is PasswordFor inside FancyBox showing my password in plain text?

I take it that this should handle masking my typed in password. But when I type in my password, it shows up as plain text.
<tr>
<td>Password:</td>
<td>
#Html.PasswordFor(u => u.Password)</td>
</tr>
Use this solution, it will work for you.
<tr>
<td>Password:</td>
<td>
#Html.Password("password", null, new { style = "float:none;margin:0;" })
</td>
</tr>

Resources