ASP:后面代码中的隐藏字段变量在更新面板中的服务器返回值丢失 [英] ASP:Hidden field variable from code behind loses value on return from server inside update panel

查看:117
本文介绍了ASP:后面代码中的隐藏字段变量在更新面板中的服务器返回值丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示报告数据的自定义Web部件.它位于选项卡控件和更新面板中,因此刷新报表数据的回调是异步的.

I have a custom webpart that displays report data. It lives inside a tab control, and inside an update panel so the call back to refresh the report data is async.

在服务器上,我需要处理一些数据并发回一个值以供以后使用.此变量只需要在那儿坐下并等待用户操作,然后客户端javascript将使用读取的变量,并基于变量的条件,该javascript将以编程方式单击"更新面板中的按钮.

On the server, I need to process some data and send back a value for later use. This variable just needs to SIT there and wait for user action, and then a client side javascript will use read the variable and based on the condition of the variable, this javascript will programmatically "click" the button in the update panel.

<asp:UpdatePanel ID="UpdatePanel1" runat="server" OnUnload="UpdatePanel_Unload">
<ContentTemplate>

<asp:Button ID="btnSendHiddenField" runat="server" style="visibility: hidden; display: none;"  OnClick="btnSendHiddenField_Click"/>

    <rsweb:ReportViewer ID="ReportViewer1" runat="server" 
        Font-Names="Verdana" Font-Size="8pt" Height="383px" 
        InteractiveDeviceInfos="(Collection)" ProcessingMode="Remote" 
        WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Width="757px" 
        SizeToReportContent="True">
    </rsweb:ReportViewer>

<asp:HiddenField  ID= "hiddenCurrentObjectId"  runat="server"/>

</ContentTemplate>
</asp:UpdatePanel>

处理数据并发送回变量的服务器代码.我已经省略了无关的代码.

Protected Sub btnSendHiddenField_Click(sender As Object, e As EventArgs) Handles btnSendHiddenField.Click
                Dim parsedObjectId As String = ""
                parsedObjectId = "1000"
                hiddenCurrentObjectId.Value = parsedObjectId
End Sub

在我的面板的OnUnload代码中.为了使某些其他东西在WebPart中起作用,必须在其中放置哪一部分.我借用了此OnUnload代码来解决之前的问题.

In my OnUnload code for the panel. Which has to be there or there to make some other things work in the WebPart. I borrowed this OnUnload code to overcome a previous issue.

Protected Sub UpdatePanel_Unload(sender As Object, e As EventArgs)
    Dim methodInfo As MethodInfo = GetType(ScriptManager).GetMethods(BindingFlags.NonPublic Or BindingFlags.Instance).Where(Function(i) i.Name.Equals("System.Web.UI.IScriptManagerInternal.RegisterUpdatePanel")).First()
    methodInfo.Invoke(ScriptManager.GetCurrent(Page), New Object() {TryCast(sender, UpdatePanel)})
End Sub
End Class

问题

隐藏字段中的值在返回行程中被清除.我认为它在OnUnload函数调用中被清除了.

THE PROBLEM

The value from the hidden field gets wiped out on the return trip. I think it is getting wiped on the OnUnload function call.

我该怎么做才能保留此隐藏字段的值,以便当另一个用户生成的事件发生时,客户端javascript可以使用它?

What can I do to preserve this hidden field value so the client side javascript can use it when another user generated event occurs?

推荐答案

如果丢失了隐藏字段值,则以最简单的方式将其存储在任何Session值的ViewState中.

If you are lossing the hidden field value then simplest way it to store it in a ViewState of any Session value.

您可以通过以下方式获得js中的值:

You can get the value in js as:

function GetSessionValue()
{
   var sessionValue = "<%=Session["ITEM"].ToString()%>";
}

这篇关于ASP:后面代码中的隐藏字段变量在更新面板中的服务器返回值丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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