Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello
I'm trying to to kinda a image filmstrip to view pics, videos etc.
For this purposes I have a UpdatePanel which is opened by the ModalPopupExtender. This UpdatePanel has two buttons - Next, Prev - and place to display image. In the UpdatePanel I have HiddenField user sto store current image index. On each click to prev/next I'm changing this value. But it apperas that thevalue is always the same - original one placed there when ModalPopup shows the modal window.
Here is the code:
ImageStrip.ascx
ASP.NET
<asp:Panel ID="pnlFullViewWindow" runat="server">
    <asp:UpdatePanel ID="pnlFullView" runat="server" Style="background-color: #FFFFFF; border: solid 1px Gray; color: Black">
        <ContentTemplate>
            <asp:HiddenField ID="hdnCurrentAssetIndex" runat="server"  /> <!-- I want to store index here -->
            <div>
                <table>
                    <tr>
                        <td>
                            <asp:ImageButton ID="btnFullViewPrev" runat="server" OnClick="btnFullViewPrev_Click" AlternateText="<<" />
                        </td>
                        <td>
                                                    <!-- controls to display image here -->
                        </td>
                        <td>
                            <asp:ImageButton ID="btnFullViewNext" runat="server" OnClick="btnFullViewNext_Click" AlternateText=">>" />
                        </td>
                    </tr>
                </table>


            </div>

        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Panel>

In the code of prev/next handlers I'm trying setting hidden field value like this:
ImageStrip.ascx.cs
C#
hdnCurrentAssetIndex.Value = CurrentAssetIndex.ToString()

In the Page_Load I'm trying to get this value like this:
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
       // something here
    }
    else
    {
       // something here

if (!string.IsNullOrEmpty( hdnCurrentAssetIndex.Value)) // it should be changed value here...
{
    this.CurrentAssetIndex = Int32.Parse(hdnCurrentAssetIndex.Value);
}


    }
}

But the value I'm obrtaining is always the same and never changes.
Can someone please help me to understand why it postback in UpdatePanel doesnt change this value? And how ti can be done in the right way?
Posted
Comments
samit kaneriya 12-Feb-14 1:00am    
after click next or previous button your hiddenfield value change right so set hf value their

1 solution

use this

XML
<asp:Panel ID="pnlFullViewWindow" runat="server">
        <asp:UpdatePanel ID="pnlFullView" runat="server">
            <ContentTemplate>
            <asp:Label ID="lblPrintValue" runat="server" Text="0"></asp:Label>
                <asp:HiddenField ID="hdnCurrentAssetIndex" runat="server" Value="0" />
                <!-- I want to store index here -->
                <div>
                    <table>
                        <tr>
                            <td>
                                <asp:ImageButton ID="btnFullViewPrev" runat="server" OnClick="btnChangeIndex_Click"
                                    AlternateText="<<" />
                            </td>
                            <td>
                                <!-- controls to display image here -->
                            </td>
                            <td>
                                <asp:ImageButton ID="btnFullViewNext" runat="server" OnClick="btnChangeIndex_Click"
                                    AlternateText=">>" />
                            </td>
                        </tr>
                    </table>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </asp:Panel>



use this in code side for test change hf value


C#
protected void btnChangeIndex_Click(object sender, ImageClickEventArgs e)
       {
           ImageButton img = (ImageButton)sender;
           if (img.ID == "btnFullViewPrev")
               hdnCurrentAssetIndex.Value = (int.Parse(hdnCurrentAssetIndex.Value) - 1).ToString();
           else
               hdnCurrentAssetIndex.Value = (int.Parse(hdnCurrentAssetIndex.Value) + 1).ToString();
           lblPrintValue.Text = hdnCurrentAssetIndex.Value;
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900