【发布时间】:2013-08-23 07:47:35
【问题描述】:
我正在开发一个向用户显示新闻的 asp.net 网站。新闻通过用户控件中的中继器显示在网站上。现在我正在尝试使用插入到中继器的 ItemTemplate 中的按钮删除这些新闻(因此按钮是动态创建的):
<asp:Button ID="DelBtn" runat="server" OnClientClick="if(!confirm('Really want to delete?')){return false;}" OnClick="cmdDeleteNews_Click" CommandArgument='<%# Eval("NewsID") %>' />
从数据库中删除不是问题。但是之后我如何使用户控件刷新,所以被删除的新闻不再显示在网站上?简单地使用 Java 脚本删除元素是可能的,但由于会有很多用户在网站上更新、插入和删除新闻,死锁很容易发生。 Reloading the Page 使用 window.location.reload() 也是可能的,但实际上没有意义。因此,我正在寻找一种解决方案来更新 PostBack 上新闻转发器的数据绑定。但是由于 DataBind()-Method 不能用于 Postback,我希望你有一个类似的解决方案来解决这个问题,或者可能是一个解决方法。 新闻中继器的 DataBind() 是在 Usercontrol 的 Codebehind 中完成的
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Databind on PostBack is not permitted (InvalidPostbackException)
If Not IsPostBack Then
NewsRepeater.DataSource = Items
NewsRepeater.DataBind()
ContentRepeater.DataSource = Items
ContentRepeater.DataBind()
End If
End Sub
【问题讨论】:
标签: asp.net data-binding