由回调事件创建的datalist在回发时丢失

时间:2013-02-04 10:23:15

标签: asp.net

我在回调事件上绑定datalist。单击datalist中的按钮需要回发以获取另一个数据列表的数据。但在回发后,页面上看不到任何数据列表。我不知道在回发时发生了什么。请帮我找一个解决方案......

 If IsPostBack = False Then
        callback = ClientScript.GetCallbackEventReference(Me, "message", "processMyResult", "context")
        Dim script As String = "function CallBack(message,context){" + callback + ";}"
        ClientScript.RegisterClientScriptBlock(Me.GetType(), "CB", script:=script, addScriptTags:=True)


        callbackhotelsearch = ClientScript.GetCallbackEventReference(Me, "message", "processhotelsearchResult", "context")
        Dim scriptsearch As String = "function callbackhotelsearch(message,context){" + callback + ";}"
        ClientScript.RegisterClientScriptBlock(Me.GetType(), "CB", script:=scriptsearch, addScriptTags:=True)

        SearchTextBox.Attributes.Add("onkeyup", "javascrpt:LookUpStock()")
        SearchTextBox.Attributes.Add("onfocus", "javascript:SetCursorToTextEnd()")
    End If





 Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent

    If (eventArgument) Is Nothing Then

        returnValue = "-1"

    Else

        binddata(eventArgument)
    End If



    Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()
    Dim sw As System.IO.StringWriter = New System.IO.StringWriter(sb)
    Dim hw As HtmlTextWriter = New HtmlTextWriter(sw)
    dataListPackages.RenderControl(hw)
    returnValue = sb.ToString()

End Sub

Public Function GetCallbackResult() _
As String Implements _
System.Web.UI.ICallbackEventHandler.GetCallbackResult

    Return returnValue

End Function

Public Function binddata(ByVal eventArgument As String) As Nullable
    Dim adp As New dsRegistrationTableAdapters.searchPackagesTableAdapter()
    Dim dt As New dsRegistration.searchPackagesDataTable()
    dt = adp.GetData(eventArgument, StartDateTextBox.Text, EndDateTextBox.Text)
    'StartDateTextBox.Text = "11-12-2012"

    dataListPackages.DataSource = dt
    dataListPackages.DataBind()
    SearchTextBox.Focus()
    Return Nothing
End Function

谢谢

1 个答案:

答案 0 :(得分:1)

初始加载后无法访问数据源项。它们仅在数据绑定中可用。

在您的情况下,您可以使用HiddenField在发布期间存储ID,然后通过该ID而不是dataitem获取数据,因为在回发后dataitem将不可用。