namespace KetBanBonPhuong.Controls.Default
{
public partial class SugFriends : System.Web.UI.UserControl
{
private string Uid;
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["UId"] != null)
{
string value = Request.Cookies["UId"].Value;
Uid = UserService.GetId_Cookie(value);
}
else
{
Uid = Session["Id"].ToString();
}
LoadListSuggest();
}
private void LoadListSuggest()
{
string str = "";
List<RankByUser> list = new List<RankByUser>();
list = RankByUserService.GetListRank(Uid);
foreach (RankByUser rank in list)
{
str += "<li><div class=\"sug_acc\">"
+ "<a href=\"/" + rank.Link + ".aspx\"><img src=\"" + rank.Avatar + "\" alt=\"avatar\"/></a>"
+ "<a href=\"/" + rank.Link + ".aspx\" class=\"sug_name\">" + rank.LastName + " " + rank.FirstName + "</a>"
+ "</div>"
+ "<div class=\"rank\">"
+ "<a href=\"#\" title=\"Xem chi tiết\" class=\"num\">rank: " + rank.Rank + "</a>"
+ "<a href=\"#\" class=\"button mycoblue\">Kết bạn</a>"
+ "</div></li>";
}
ltrListSug.Text = str;
}
}
}`
是在
SugFriends.ascx
中添加的用户控件Default.Master
当我单击
"a.button"
回发到服务器事件时(我想向数据库中插入数据,我使用了Sql server)怎么做?使标记成为事件
onclick
'喜欢'LinkButton: Onclick()
?感谢您的帮助!我找到解决该问题的方法!我为每个标签a使用了Ajax onclick,事件发布了Ajax.aspx,在这里我可以对数据库进行编码!
最佳答案
将onclick="(javascript:__doPostBack('','');"
属性添加到<a>
标记以通过Javascript执行回发。像这样:
+ "<a href=\"#\" class=\"button mycoblue\" onclick=\"(javascript:__doPostBack('','');\">Kết bạn</a>"
More details here
对评论的回应:
尝试在页面上创建一个按钮
<asp:Button ID="btnPlaceHolder" Visible="False" runat="server" />
,然后按照我在此解决方案中所说的做,而是使用__doPostBack('<%=btnPlaceHolder.UniqueID %>', '')
从那里,您可以使用方法块
Private Sub btnPlaceHolder_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPlaceHolder.Click
运行您想要回发的代码。