ASP:从code隐藏字段变量后面失去从服务器UDPATE面板内部的返回值 [英] ASP:Hidden field variable from code behind loses value on return from server inside udpate panel

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

问题描述

我有一个显示报告数据的自定义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>

服务器code处理数据并发送回变量。我省略无关code。

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的code为面板。其中有在那里或者有做一些其他的东西在的WebPart工作。我借这个onunload的code克服previous问题。

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.

我能做些什么,以preserve这个隐藏字段的值,因此客户端的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?

感谢这么多的任何帮助或洞察力。我真的AP preciate它。我会死没有这个论坛:):):)

Thanks so much for any help or insight. I really appreciate it. I would die without this forum :):):)

推荐答案

如果你是损耗隐藏字段值,那么最简单的方法是将其存储在任意会话价值的ViewState中。

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

您可以在JS的值:

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

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

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