更新面板中的图像未获得更新

时间:2012-03-04 11:35:29

标签: asp.net ajax asp.net-ajax updatepanel

我正在处理Image Album之类的事情。最初将在更新面板中放置的IMG服务器控件中加载一个图像。单击Next按钮,下一个图像必须在更新面板中加载,代码为在类后面的代码中给出..虽然按钮点击被正确调用..按钮点击图像没有改变

这是我的页面

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div id="Container">
    <table border="0">
        <tr>
            <td align="left">
                <asp:ImageButton ID="cmdPrevious" runat="server" ImageUrl="/Images/GoPrevious.png"
                    Height="40" />
            </td>
            <td align="center">
                Album : Image (5/10)
            </td>
            <td align="right">
                <asp:ImageButton ID="cmdNext" runat="server" ImageUrl="/Images/GoNext.png" Height="40" />
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <asp:Image ID="AlbumImage" runat="server" />
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="cmdNext" EventName="Click" />
                        <asp:AsyncPostBackTrigger ControlID="cmdPrevious" EventName="Click" />
                    </Triggers>
                </asp:UpdatePanel>
            </td>
        </tr>
    </table>
</div>

现在这是背后的代码..

Partial Class view
Inherits System.Web.UI.Page
Public fun As New functions
Public AlbumType, AlbumName, ImageUrl As String
Public ImgArray As String(,)

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    Dim Pid As Integer
    Dim TName As String
    AlbumType = Request.QueryString("AlbumType")
    AlbumName = Request.QueryString("AlbumName")
    ImageUrl = Request.QueryString("ImageUrl")
    Pid = fun.GetAlbumID(AlbumType & "/" & AlbumName & "/" & ImageUrl)
    TName = fun.GetTags4MefrmID(Pid)
    ImgArray = fun.getAlbumImages(TName, Pid)
    AlbumImage.ImageUrl  = "http://Sitename/Gallery/var/Albums/" & ImgArray(0, 2)


End Sub

Protected Sub cmdNext_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles cmdNext.Click
    AlbumImage.ImageUrl  = "http://sitename/Gallery/var/Albums/" & ImgArray(1, 2)

End Sub

结束班

请帮助我找到一种方法,在按钮单击

上更改更新面板中的图像

1 个答案:

答案 0 :(得分:0)

移动你的page_load代码而不是Postback,你将重新绑定到page_load中的默认图像,这将覆盖你在事件点击时设置的图像。

例如:

If(Not Page.IsPostBack) then
 AlbumImage.ImageUrl  = "http://Sitename/Gallery/var/Albums/" & ImgArray(0, 2)
END