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.

AMDI
  • 895
  • 2
  • 17
  • 40
  • Possible duplicate of https://stackoverflow.com/questions/532227/how-to-migrate-existing-asp-net-application-to-asp-net-mvc-pattern-format – Miller Cy Chan Jun 21 '23 at 01: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 – AMDI Jun 21 '23 at 02:47
  • You may refer to https://stackoverflow.com/questions/7772662/aspx-works-but-ascx-does-not-why-and-how-to-fix – Miller Cy Chan Jul 04 '23 at 07:45

0 Answers0