我无法在转发器内回传UpdatePanel。
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:Repeater ID="Posts" runat="server" OnItemCreated="Posts_OnItemCreated">
<ItemTemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Label ID="lblComentarios" runat="server" Text='<%# Eval("LabelComentarios") %>'></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click"/>
</Triggers>
</asp:UpdatePanel>
<asp:TextBox ID="txtComentario" runat="server" CssClass='<%# Eval("PostId") %>'></asp:TextBox>
<asp:Button ID="Button1" ClientIDMode="Static" runat="server" OnCommand="btnComentar_OnCommand" CommandName='<%# Eval("PostId") %>' class='<%# Eval("PostId") %>' />
</ItemTemplate>
</asp:Repeater>
转发器的代码OnItemCreated():
protected void Posts_OnItemCreated(object sender, RepeaterItemEventArgs e)
{
var control = e.Item.FindControl("Button1");
ScriptManager.GetCurrent(Page).RegisterAsyncPostBackControl(control);
}
然后在我的代码隐藏OnCommand ..
protected void btnComentar_OnCommand(object sender, CommandEventArgs e)
{
MyCode();
foreach (RepeaterItem item in Posts.Items)
{
var panel = (UpdatePanel)item.FindControl("UpdatePanel1");
panel.Update();
}
}
除了panel.update()之外,一切都在做它应该做的事情。
答案 0 :(得分:0)
我已完成以下代码及其更新测试值以标记
ASPX:
public void OnActionExecuting(ActionExecutingContext filterContext)
{
try
{
var attribute = filterContext.ActionDescriptor.GetCustomAttributes(typeof(AuthoriseAction), false).SingleOrDefault() as AuthoriseAction;
if (attribute != null)
{
var userID = _cookieManager.DecryptFormsAuthenticationCookie(filterContext.HttpContext);
if (userID == -1) { filterContext.Result = new Http401Result(); return; }
var user = _userManager.LoadByIDSync(userID);
var isAuthenticated = _authenticator.AuthenticateUserSync(user);
...
}
}
代码背后:
<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeBehind="Test.aspx.cs" Inherits="WebApplication1.Test" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:Repeater ID="Posts" runat="server" OnItemCreated="Posts_OnItemCreated">
<ItemTemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblComentarios" runat="server" Text='<%# Eval("LabelComentarios") %>'></asp:Label>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("LabelComentarios") %>'></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:TextBox ID="txtComentario" runat="server" CssClass='<%# Eval("PostId") %>'></asp:TextBox>
<asp:Button ID="Button1" ClientIDMode="Static" runat="server" OnCommand="btnComentar_OnCommand" CommandName='<%# Eval("PostId") %>' class='<%# Eval("PostId") %>' />
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
同时检查!IsPostback是否正确