简体   繁体   中英

Creating User Control works with AJAX

I need to create a user control with 3 images: like, dislike and comment buttons. I want to like and dislike button to save some info to the database (liked user and liked object). But i want to work them without reloading the page.

Example scenario:

  • Like button shows like count if the post has any
  • User likes a blog post.
  • Save like process to the DB
  • Disable like button.

I want to implement this operation via AJAX call to the page in which the control is used, inside of the control. I don't want to implement them separately. When another developer wanted to use this, he/she must use the control just by instantiating. Also, it must be used more than once in a page.

Regards.

Put your buttons inside an update panel in the user control.

This Introduction to the UpdatePanels will get you started.

Then other developers can use you control on any other page without any trouble.

Update panels are server controls that internally make ajax calls and update their contents.
Should work perfectly for what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM