开发者

run serverside method from jquery

开发者 https://www.devze.com 2023-02-25 18:13 出处:网络
I know the method that, from jQuery, using ajax I can invoke WebMethod from a aspx or asmx file. That\'s ok, but I only can place my project logic in ascx.cs files. It is a specific CMS and I can\'t d

I know the method that, from jQuery, using ajax I can invoke WebMethod from a aspx or asmx file. That's ok, but I only can place my project logic in ascx.cs files. It is a specific CMS and I can't do anything about it.

So my question is based on example described below:

Lets say users is logged in and is viewing an article. One user开发者_开发问答 wants to mark it as a favourite, so clicks a button. On the server side without, refreshing the page, an appropriate method should run which adds this article to his favourites and then in client side there is an alert - 'Success'.

I dont want anyone to write the code for me for that it is just an example for desribing what functionality I would like to be able to achieve and which technology to use for that.

Thanks for the help.

P.S. I'm using ASP.Net 2.0


ASCX files are not directly accessible from the client (and as such, cannot be targeted via AJAX calls).

If your logic really has to be encapsulated in the ASCX file, you can add in an entrypoint WebMethod in your ASPX that calls the respective ASCX method instead. You'll probably encounter some difficulties related to the WebMethods being static though, so you may eventually need to refactor a bit, depending on how your code is structured now.


You can make ajax call to remote page (with ascx control with your server side method) and then parse output (for example look for world "SUCCESS") to verify, that your method is executed. Not very elegant, but it will work.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号