How do I get the id of a textbox in a grid when it is in edit mode?
I have a grid and when I am in edit mode I want to pass the email address typed into the textbox to the controller via ajax and see if the already registered.
Here is my code so far, which by the way works if I was just filling in a standard form!
The grid:
@(Html.Kendo().Grid<ExternalTrainingDashboard.ViewModel.TraineeViewModel>()
.Name("grid")
.Columns(columns =>
{
columns.ForeignKey(p => p.TitleID, (System.Collections.IEnumerable)ViewData["titles"], "TitleID", "Title");
columns.Bound(p => p.FirstName);
columns.Bound(p => p.LastName);
columns.Bound(p => p.EmailAddress);
columns.Command(command =>
{
command.Edit();
});
})
.ToolBar(toolBar =>
{
toolBar.Create().Text("Create New Trainee");
})
.Editable(editable => editable.Mode(GridEditMode.InLine))
.DataSource(dataSource => dataSource
.Ajax()
.Events(events => events.Error("error_handler"))
.Model(
model =>
{
model.Id(p => p.TraineeID);
})
.Read(read => read.Action("Trainee_Read", "Trainee"))
.Update(edit => edit.Action("Trainee_Update", "Trainee"))
.Create(create => create.Action("Trainee_Create", "Trainee"))
)
)
And my javascript:
<script type="text/javascript">
$(function () {
var msg = $("#emailaddress-message");
$("#EmailAddress").blur(function () {
var emailaddress = $(this).val();
if (emailaddress.length == 0) {
alert("No Email Address.");
return;
}
$.ajax({
url: '@Url.Action("CheckForUniqueEmail", "Trainee")',
dataType: 'json',
type: 'GET',
data: { EmailAddress: emailaddress },
success: OnCheckForUniqueUserSuccess,
error: OnCheckForUniqueUserError
});
});
function OnCheckForUniqueUserSuccess(data) {
if (data.Exists) {
msg.text("This Email Address is already in use. Please enter a new one.");
btn.attr("disabled", "disabled");
} else {
msg.text("");
btn.removeAttr("disabled");
}
}
function OnCheckForUniqueUserError(xhr, status, error) {
msg.text("There was an error checking uniqueness.");
}
});
</script>
But the blur function is not triggering, I am guess this in because I don't have the correct id of the email address text box??
I have a grid and when I am in edit mode I want to pass the email address typed into the textbox to the controller via ajax and see if the already registered.
Here is my code so far, which by the way works if I was just filling in a standard form!
The grid:
@(Html.Kendo().Grid<ExternalTrainingDashboard.ViewModel.TraineeViewModel>()
.Name("grid")
.Columns(columns =>
{
columns.ForeignKey(p => p.TitleID, (System.Collections.IEnumerable)ViewData["titles"], "TitleID", "Title");
columns.Bound(p => p.FirstName);
columns.Bound(p => p.LastName);
columns.Bound(p => p.EmailAddress);
columns.Command(command =>
{
command.Edit();
});
})
.ToolBar(toolBar =>
{
toolBar.Create().Text("Create New Trainee");
})
.Editable(editable => editable.Mode(GridEditMode.InLine))
.DataSource(dataSource => dataSource
.Ajax()
.Events(events => events.Error("error_handler"))
.Model(
model =>
{
model.Id(p => p.TraineeID);
})
.Read(read => read.Action("Trainee_Read", "Trainee"))
.Update(edit => edit.Action("Trainee_Update", "Trainee"))
.Create(create => create.Action("Trainee_Create", "Trainee"))
)
)
And my javascript:
<script type="text/javascript">
$(function () {
var msg = $("#emailaddress-message");
$("#EmailAddress").blur(function () {
var emailaddress = $(this).val();
if (emailaddress.length == 0) {
alert("No Email Address.");
return;
}
$.ajax({
url: '@Url.Action("CheckForUniqueEmail", "Trainee")',
dataType: 'json',
type: 'GET',
data: { EmailAddress: emailaddress },
success: OnCheckForUniqueUserSuccess,
error: OnCheckForUniqueUserError
});
});
function OnCheckForUniqueUserSuccess(data) {
if (data.Exists) {
msg.text("This Email Address is already in use. Please enter a new one.");
btn.attr("disabled", "disabled");
} else {
msg.text("");
btn.removeAttr("disabled");
}
}
function OnCheckForUniqueUserError(xhr, status, error) {
msg.text("There was an error checking uniqueness.");
}
});
</script>
But the blur function is not triggering, I am guess this in because I don't have the correct id of the email address text box??