Asp.net 使更新面板组件更改项目在更新面板外部的可见性
我有一个转发器,项目可以通过编辑按钮进行编辑,该按钮在编辑模式下打开FormView。formView最初不可见,中继器可见。按下“编辑”后,转发器将不可见,然后formview将与要编辑的项目一起可见 更改完成后,用户按update。这将formview设置为不可见,中继器设置为可见 问题是formview不可见,但中继器不可见。我认为这是因为formview在更新面板中,而中继器不在更新面板中?只有更新面板中的项目在单击更新时被更改,因为它只是部分页面更新 我不能将repeater放在更新面板中,因为有一个要求公共视图不使用javascript 有人知道我怎样才能让中继器重现吗Asp.net 使更新面板组件更改项目在更新面板外部的可见性,asp.net,asp.net-ajax,updatepanel,repeater,formview,Asp.net,Asp.net Ajax,Updatepanel,Repeater,Formview,我有一个转发器,项目可以通过编辑按钮进行编辑,该按钮在编辑模式下打开FormView。formView最初不可见,中继器可见。按下“编辑”后,转发器将不可见,然后formview将与要编辑的项目一起可见 更改完成后,用户按update。这将formview设置为不可见,中继器设置为可见 问题是formview不可见,但中继器不可见。我认为这是因为formview在更新面板中,而中继器不在更新面板中?只有更新面板中的项目在单击更新时被更改,因为它只是部分页面更新 我不能将repeater放在更新面
<asp:Repeater id="resultsRepeater" runat="server" DataSourceID="vehiclesDataSource" >
<ItemTemplate>
<asp:Label id="makeLabel" runat="server" Text='<%# Eval("Make") %>' />
<asp:Button id="editButton" runat="server" Text="Edit" CommandArgument='<%# Eval("Id") %>' OnClick="EditButton_Click" />
</ItemTemplate>
<asp:Repeater>
<asp:UpdatePanel ID="updatePanel" runat="server">
<ContentTemplate>
<asp:Panel id="insertUpdatePanel" runat="server" Visible="false">
<asp:FormView id="editformview" runat="server" DataKeyNames="Id" Datasourceid="VehiclesEditDataSource" >
<EditItemTemplate>
<uc:VehiclesEdit ID="VehiclesEdit" runat="server" />
<asp:Button id="updateButton" runat="server" OnClick="Update_Click" />
</EditItemTemplate>
</asp:FormView>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
protected void EditButton_Click(object sender, EventArgs e)
{
resultsRepeater.Visible = false;
insertUpdatePanel.Visible = true;
}
protected void Update_Click(object sender, EventArgs e)
{
resultsRepeater.Visible = true;
insertUpdatePanel.Visible = false;
}
受保护的无效编辑按钮\u单击(对象发送者,事件参数e)
{
resultsRepeater.Visible=false;
insertUpdatePanel.Visible=true;
}
受保护的无效更新\u单击(对象发送者,事件参数e)
{
resultsRepeater.Visible=true;
insertUpdatePanel.Visible=false;
}
修订版:在UpdatePanel中添加PostBackTrigger,以在单击UpdateButton时强制执行完整的回发。这将隐藏你的UpdatePanel并再次显示你的转发器。见下面的最终代码:
有关更多信息,请参阅:
这可能会有所帮助。我也有类似的问题,这对我来说很有效。我只是使用ScriptManager将按钮(甚至按行迭代)注册为回发控件,如下所示:
ScriptManager.GetCurrent(Page).RegisterPostBackControl(updateButton)
这导致了完整的回发,并允许我设置更新面板外部面板的可见性。我希望它能起作用 是的,这可能会起作用,但是updateButton可见性不再与FormView的内容同步。上面的修订应该可以解决这个问题。按照stackoverflow链接了解更多信息。希望能有帮助。
ScriptManager.GetCurrent(Page).RegisterPostBackControl(updateButton)