使用 Asp.Net ListView 和 Asp.Net Ajax 更新面板
您好,我希望这对某人来说很容易回答。首先,我试图将 ListView
绑定到 DataPager
并放入 ASP.NET UpdatePanel
来制作一个 AJAX 支持的寻呼机我的数据库中的记录。我抓住了一个 UpdatePanel
并放置了:
SqlDataSource
ListView
- 具有ItemTemplate
包括一个ImageButton
中的其他几个 ASP.NET 控件- 中的
DataPager
> 以及ContentTemplate
。将 DataPager
ID 分配给 UpdatePanel
触发器字段中的 AsyncPostbackTrigger
效果非常好。
我还想在 ImageButton
Click
事件中执行完整的回发。但是,由于 ImageButton
位于 ListView
内部,因此 UpdataPanel
会导致部分回发。我尝试将 ImageButton 添加为 UpdatePanel
PostBackTrigger
,但 UpdatePanel
需要控件 ID,并且不会接受 ImageButton< /code> 因为它位于
ListView
内部。
如何向其传递 ListView
的 ItemTemplate
内元素的控件 ID 并成功导致完整回发?
这是我的代码:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:SqlDataSource ... ></asp:SqlDataSource>
<asp:ListView ID="ListViewForAlbums" runat="server" >
<ItemTemplate>
<div class="album">
<asp:ImageButton ID="albumPhoto" class="albumPhotosStyle" runat="server" ImageUrl="<%# Bind('albumPhotoPath') %>" AlternateText="<%# Bind('album_id') %>" ToolTip="<%# Bind('albumDetails') %>" onclick="albumPhotos_Click" />
<div class="albumInfoHolder">
...
</div>
</div> <!-- End Album -->
</ItemTemplate>
<EmptyDataTemplate>
<p>No Albums Yet. Check Back Soon!</p>
</EmptyDataTemplate>
</asp:ListView>
<asp:DataPager ID="DataPagerForAlbums" runat="server" PagedControlID="ListViewForAlbums" PageSize="3" >
<Fields>
<asp:NextPreviousPagerField ShowFirstPageButton="True" FirstPageText="«" ShowNextPageButton="False" ShowPreviousPageButton="false" />
<asp:NumericPagerField />
<asp:NextPreviousPagerField ShowLastPageButton="True" LastPageText="»" ShowPreviousPageButton="False" ShowNextPageButton="false" />
</Fields>
</asp:DataPager>
</p>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DataPagerForAlbums" />
</Triggers>
</asp:UpdatePanel>
Hello there, I hope this will be easy for someone to answer. First off I was trying to make a ListView
bound to a DataPager
and put in an ASP.NET UpdatePanel
to make an AJAX-powered pager for the records from my database. I grabbed an UpdatePanel
and I placed:
SqlDataSource
ListView
- havingItemTemplate
including oneImageButton
and several other ASP.NET controls in itDataPager
in the ContentTemplate
. Assigning the DataPager
ID to the AsyncPostbackTrigger
in the UpdatePanel
's trigger fields worked perfectly.
I also wanted to perform a full post-back in the ImageButton
Click
event. However, because the ImageButton
is inside the ListView
, the UpdataPanel
causes a partial post-back. I tried adding the ImageButton as an UpdatePanel
PostBackTrigger
, but the UpdatePanel
demands a control ID, and won't accept the ImageButton
since it is inside the ListView
.
How do I pass it a control ID for an element inside ItemTemplate
of the ListView
and successfully cause a full post back?
Here is my code:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:SqlDataSource ... ></asp:SqlDataSource>
<asp:ListView ID="ListViewForAlbums" runat="server" >
<ItemTemplate>
<div class="album">
<asp:ImageButton ID="albumPhoto" class="albumPhotosStyle" runat="server" ImageUrl="<%# Bind('albumPhotoPath') %>" AlternateText="<%# Bind('album_id') %>" ToolTip="<%# Bind('albumDetails') %>" onclick="albumPhotos_Click" />
<div class="albumInfoHolder">
...
</div>
</div> <!-- End Album -->
</ItemTemplate>
<EmptyDataTemplate>
<p>No Albums Yet. Check Back Soon!</p>
</EmptyDataTemplate>
</asp:ListView>
<asp:DataPager ID="DataPagerForAlbums" runat="server" PagedControlID="ListViewForAlbums" PageSize="3" >
<Fields>
<asp:NextPreviousPagerField ShowFirstPageButton="True" FirstPageText="«" ShowNextPageButton="False" ShowPreviousPageButton="false" />
<asp:NumericPagerField />
<asp:NextPreviousPagerField ShowLastPageButton="True" LastPageText="»" ShowPreviousPageButton="False" ShowNextPageButton="false" />
</Fields>
</asp:DataPager>
</p>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DataPagerForAlbums" />
</Triggers>
</asp:UpdatePanel>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 ScriptManager 将控件注册为回发控件。在
ItemDataBound
事件中执行类似的操作:You can use the ScriptManager to register the control as a postback control. Do something like this in the
ItemDataBound
event:使用 ItemDataBound ListView 的事件获取 ImageButton 并使用 ScriptManager 的 RegisterPostBackControl 方法将其注册为回发控件。
Use a ItemDataBound ListView's event to get ImageButton and register it as a postback control with ScriptManager's RegisterPostBackControl method.