UpdatePanel - 无法在回发时更改HiddenField值 [英] UpdatePanel - can't change HiddenField Value on postback

查看:103
本文介绍了UpdatePanel - 无法在回发时更改HiddenField值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我正试图通过图片幻灯片查看图片,视频等。

为此,我有一个由ModalPopupExtender打开的UpdatePanel 。此UpdatePanel有两个按钮 - Next,Prev - 和显示图像的位置。在UpdatePanel中,我有HiddenField用户sto存储当前图像索引。每次点击上一个/下一个我都会改变这个值。但是看起来这个值总是一样的 - 当ModalPopup显示模态窗口时,原始值就放在那里。

这是代码:

ImageStrip.ascx

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: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>



在prev / next handlers的代码中我正在尝试像这样设置隐藏字段值:

ImageStrip.ascx.cs


In the code of prev/next handlers I'm trying setting hidden field value like this:
ImageStrip.ascx.cs

hdnCurrentAssetIndex.Value = CurrentAssetIndex.ToString()



在Page_Load中我试图得到这样的值:


In the Page_Load I'm trying to get this value like this:

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);
}


    }
}



但我所看到的价值是总是一样的,永远不会改变。

有人可以帮助我理解为什么它在UpdatePanel中回发不会改变这个值吗?如何才能以正确的方式完成?


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?

推荐答案

使用这个



use this

<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>







在代码端使用此代码进行测试更改hf值








use this in code side for test change hf value


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;
       }


这篇关于UpdatePanel - 无法在回发时更改HiddenField值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆