I am currently working on one application where I have this old application code written in classic asp. For one enhancement requirement I have added an .aspx page in that application (as I prefer asp.net over classic asp).
My .aspx page contains some markup and jQuery code (some event change code) along with an ajax call to the server side web method. [As a separate solution (asp.net), my .aspx code works perfectly but when I integrate that .aspx page in classic asp application, jQuery ajax call to server side web method never reaches. It always throws error. (I have used closures).] Is it really possible which I am trying to achieve? If yes, HOW? Or what could be the cause of error?
I have also tried removing the ajax code segment from .aspx and tried writing the same event change code at server side.. DOESN'T WORK either. Any suggestions would be appreciated.
EDIT:
jQuery ajax call -
$.ajax({
type: "POST",
url: "xyz.aspx/someMethod",
data: "{sampleString: '" + sampleString+ "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
success: function (data) {
//success
},
error: function (data) {
alert("Error : " + data.d); //Error is thrown here - Undefined.
}
});
});
web method -
[WebMethod]
public static string someMethod(string sampleString)
{
try
{
//my actual code logic
}
catch (Exception ex)
{}
}
This above code segment works abosultely fine when I run the code in my asp.net solution. But I have a requirement where I need to take out this individual .aspx page (along with .aspx.cs obviously) and keep it in classic asp application's virtual directory. All the other pages in this application are .asp page (VB script) and we have only one different page i.e. .aspx.
So in order to host and run this classic asp app in IIS, I have created a virtual directory of the same and then put my .aspx and .aspx.cs pages alone in that directory. (No web.config, no app_start, no app_code folders at all. Just the two files) I am able to load the .aspx page in browser from that directory. I can see the actual page rendered in browser. But the functionality just doesn't work at all.
After hundreds of trials and errors, I have come to a conclusion that the scenario I am trying achieve or make it work, is not possible in my case. I'd put my .aspx page (.aspx and .aspx.cs) alone in the classic asp applications directory. Page renders successfully without any issues. But after the page has loaded fully, if i try to execute any server side code written in that .aspx page, it doesn't work. The script code written (jquery) runs only to the extent where it needs to call the client side code only. Cannot call the server side methods once the .aspx page is served (i.e. only page_load event and its allied method work). You simply cannot call the page methods again from the same page (since the page_load has already been fired. Also no other events get fired like button_click or dropdownIndex_changed etc.) Probable cause - There is no runtime environment hosting your .aspx page. All the .aspx page (while it is first served) is being treated/executed by classic asp as a 'command'. However I am still studying this behavior on the root level.
Any more suggestions or thoughts are welcome though.