Saturday, 24 August 2013

Calling Jquery function from .Net, with parameters

Calling Jquery function from .Net, with parameters

I have a .Net method which does some validation on an object, and then, I
need to display the issues to the user.
I am trying to use a jquery message box I found:
The jquery function:
function ShowPopup() {
$.msgBox({
title: "Unable to save",
content: "An error has occured while saving the object."
});
}
I need to call that from a .Net method, passing it a List of strings. Is
that possible? And then set the content property to be the list of errors?
My .Net saving method, which may trigger this popup, looks like this:
protected void btnSave_Click(object sender, EventArgs e)
{
var o = new UserDto
{
DisplayName = txtName.Text,
Email = txtEmail.Text,
Username = txtUsername.Text,
Password = txtPassword.Text,
TimeZoneId = ddZones.SelectedValue,
Id = Session["SelectedUserId"] == null ? 0 :
int.Parse(Session["SelectedUserId"].ToString())
};
var result = new UserService(Common.CurrentUserId()).SaveUser(o);
if (result.Success == false)
{
// Show an error.
return;
}
Response.Redirect("users.aspx");
}
If, if success is false, I want to pass it a list of errors, and show that
popup.
The jquery function is from here.

No comments:

Post a Comment