Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 691
  • Last Modified:

Cannot assign to a function result

function Save()
  {
      if (EmployeeDetailsValidation())
      {
          $.ajax(
              {
                  type: "POST",
                  url: "Registration.aspx/Save",
                  data: "{'firstName': '" + $("#txtFirstName").val() + "','middleName': '" + $("#txtMiddleName").val() + "','lastName': '" + $("#txtLastName").val() + "','genderId': '" + $("#ddlGender").val() + "','divisionId': '" + $("#ddlDivision").val() + "','positionId': '" + $("#ddlPosition").val() + "'}",
                  contentType: "application/json; charset=utf-8",
                  dataType: "json",
                  success: function ()
                  {
                    ClearEmployeeDetails();
                  },
                  error: function ()
                   {
                      alert("error");
                  }
              });
          }

      return false;
  }

function EmployeeDetailsValidation() {
      var isValid = false;

      if ($("#txtFirstName").val() != '' && $("#txtLastName").val() != '' && $("#ddlGender").get(0).selectedIndex != 0 &&
         $("#ddlDivision").get(0).selectedIndex != 0 && $("#ddlPosition").get(0).selectedIndex != 0) {

          isValid = true;
         }

      return isValid;
  }

function ClearEmployeeDetails()
  {
      $("#txtFirstName").val() = '';
      $("#txtMiddleName").val() = '';
      $("#txtLastName").val() = '';
      $("#ddlGender").get(0).selectedIndex = 0;
      $("#ddlDivision").get(0).selectedIndex = 0;
      $("#ddlPosition").get(0).selectedIndex = 0;
      $("#ddlPosition").attr("disabled", "disabled");
  }

 [WebMethod]
        public static void Save(string firstName, string middleName, string lastName, string genderId,
            string divisionId, string positionId)
        {
            try
            {
                Model.Employee employeeDetails = new Model.Employee();

                employeeDetails.EmployeeId = Guid.NewGuid();
                employeeDetails.FirstName = firstName;
                employeeDetails.MiddleName = middleName;
                employeeDetails.LastName = lastName;
                employeeDetails.GenderId = new Guid(genderId);
                employeeDetails.DivisionId = new Guid(divisionId);
                employeeDetails.PositionId = new Guid(positionId);

                Model.EmployeeRegistrationDC.Ins.Save(employeeDetails);
            }
            catch (Exception ex)
            {
               
                throw ex;
            }
        }

How to call  a function in a sucess function();

In success function, I am calling a  function "ClearEmployeeDetails() "
 to clear  the values, but I am getting javascript exeception "Cannot assign to a function result".

what is wrong in it and how to call a function in success function()

Is't possible to pass object  or  collection object in a query string to the page method, instead of passing values

data: "{'firstName': '" + $("#txtFirstName").val() + "','middleName': '" + $("#txtMiddleName").val() + "','lastName': '" + $("#txtLastName").val() + "','genderId': '" + $("#ddlGender").val() + "','divisionId': '" + $("#ddlDivision").val() + "','positionId': '" + $("#ddlPosition").val() + "'}",

Here I want to pass object or collection object.If we pass the object , how to convert the object to the custom object type(i.e. which we define as a parameter in pagemethod).

How to collection the data in the form of object or collection object in jQuery and how to pass it?

eg; {webMethod]
Public Static Void Save(Employee obj)
{
}

{webMethod]
Public Static Void Save(List<Employee> obj)
{
}

0
kravindra
Asked:
kravindra
1 Solution
 
Steve KrileCommented:
Just for the sake of clarity, could you post the html for these functions?  Just the form elements should be enough.
0
 
Albert Van HalenAnalyst developerCommented:
In order to clear a textbox use val("");
$("#txtFirstName").val('');

Open in new window

0
 
hieloCommented:
>>How to call  a function in a sucess function();
The way you are calling it is correct

>>"Cannot assign to a function result"
These:
  $("#txtFirstName").val() = '';
  $("#txtMiddleName").val() = '';
  $("#txtLastName").val() = '';

should be:


  $("#txtFirstName").val("")';
  $("#txtMiddleName").val("")';
  $("#txtLastName").val("")';

OR:

  $("#txtFirstName").get(0).value = '';
  $("#txtMiddleName").get(0).value = '';
  $("#txtLastName").get(0).value = '';
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now