Solved

Cannot assign to a function result

Posted on 2011-03-17
3
646 Views
Last Modified: 2012-05-11
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
Comment
Question by:kravindra
3 Comments
 
LVL 16

Expert Comment

by:Steve Krile
ID: 35156897
Just for the sake of clarity, could you post the html for these functions?  Just the form elements should be enough.
0
 
LVL 19

Accepted Solution

by:
Albert Van Halen earned 500 total points
ID: 35157094
In order to clear a textbox use val("");
$("#txtFirstName").val('');

Open in new window

0
 
LVL 82

Expert Comment

by:hielo
ID: 35158740
>>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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question