简体   繁体   English

创建用户控件可与AJAX一起使用

[英]Creating User Control works with AJAX

I need to create a user control with 3 images: like, dislike and comment buttons. 我需要创建一个包含3张图片的用户控件:“喜欢”,“不喜欢”和“评论”按钮。 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. 我想通过AJAX调用来实现该操作,该页面在控件内部使用了该控件。 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. UpdatePanels简介将帮助您入门。

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. 更新面板是服务器控件,可在内部进行ajax调用并更新其内容。
Should work perfectly for what you want. 应该可以完美地满足您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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