0

I am having a default.js file in shared folder. Dynamically we will send aspx file name and function name and the parameters to call corresponding aspx page and method.

Default.js method

function ValidateParams(fromdate,Id)
{
 var exp=/^((((0?[13578])|(1[02]))[\/]((0?[1-9]|[0-2][0-9])|(3[01])))|(((0?[469])|(11))[\/]((0?[1-9]|[0-2][0-9])|(30)))|(0?[2][\/](0?[1-9]|[0-2][0-9])))[\/]\d{4}$/;
 var exp1=/^(\d{9})$/;
 if(exp.test(fromdate)&& exp1.test(Id)) 
 {
   CheckValidityofId("FormUI.CheckValidity",fromdate,Id)
 }
}

function CheckValidityofId(lookupFunction,fromdate,Id) {

    callback = function(response) {
    
        if (response.error) {
            alert(response.error);
        }
        else {
        
            if (response.value =="NotAssociated")
            {
            document.getElementById(MessageID).innerText="Number is not associated";
            }
            else
            {
            document.getElementById(MessageID).innerText="This is NOT eligible";
            }
            
            
        }
    }
    if (fromdate.length > 0 && Id.length >0) {
        eval(lookupFunction + "('" + fromdate + "','" + Id "'," + callback + ")");
    }
    return false;
}

Here is my FormUI.ascx.cs method

public partial class FormUI : UIView
{
  public string CheckValidity(string FromDate, string Id)
  {
          // logic goes here
  }
}

Please correct me what's the wrong why the above code is not working. Its not hitting the 'CheckValidity' method in ascx.cs file. Even I tried with the below code but its's also not working

$.getJSON("Form1003UI.ascx\CheckEligibility", {
            Data: {
                FromDate: fromdate,
                Id: Id
              }, }, function (data) {
            // do stuff on callback
        });

Please let me know what is missing.

4
  • Possible duplicate of stackoverflow.com/questions/532227/… Commented Jun 21, 2023 at 1:20
  • @MillerCyChan The Post you shared is converting asp.net to MVC which we are not trying to do migration. Please suggest how to call the asp.net method from javascript file Commented Jun 21, 2023 at 2:47
  • You may refer to stackoverflow.com/questions/7772662/… Commented Jul 4, 2023 at 7:45
  • There are 3 variations of the name 'CheckValidity' in the code(s), fwiw: CheckValidity, CheckValidityofId and CheckEligibility. Commented Jan 15, 2024 at 3:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.