Not sure if my requirement is bit weird… However, i need to call a method which is resided in .ascx.cs page from mvc on button click
in MVC
i have button in layout page
<input type="button" id="btnHomeSearch" value="Search Page" />
on click of this button i have a jquery POST method which is intended to call the .ascx (ASP.NET usercontrol method) method.
$('#btnHomeSearch').click(function () {
$.ajax({
url: 'SDLCSearch.ascx.cs/HomePageSearch',
success: function (data) {
debugger;
}
});
});
which is not working… Can anyone please help..
You’re mixing up client and server code. You’re also mixing up MVC and web forms, but guess you know that, and have them in separate projects etc.
If you want to post data to a UserControl (.ascx), you’ll need to place the UserControl on a normal page (.aspx), and pass the method call through from the .aspx.cs to the .ascx.cs file appropriately.
The post method you have should be posting to the URL of the .aspx page, e.g. ‘/SDLCSearch.aspx’