2012-04-24 9 views
1

我有一個系統,在一個頁面上有一個更新面板的GridView。在選擇GridView的一行時,系統使用該CommandName和CommandArgument發佈所選行,然後將Session變量設置爲所選發佈行的ID。其他控件正確運行Async,並且已在RowDataBound事件中使用此方法註冊了該按鈕。是否可以在回發事件後運行最終函數vb?

Dim gvRowSelect As GridViewRow = e.Row 
Dim imbSelect As ImageButton = DirectCast(gvRowSelect.FindControl("imbSelect"), ImageButton) 
ScriptManager.GetCurrent(Page).RegisterPostBackControl(imbSelect) 

我想嘗試和按鈕命令,不知何故母版頁中得到這個會話,標籤設置爲當前會話。在imbSelect命令的代碼是:

Dim cellSnapshot As TableCell = gvSnapshots.Rows(e.CommandArgument).Cells(0) 
Session("Snapshot") = cellSnapshot.Text 

在母版反正是有在Page_Load後調用一個函數,並經過它解決所有的回發事件?

謝謝。所有的回發事件已經完成

 Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)  Handles Me.PreRender 

    End Sub 

+0

您是否嘗試過[LoadComplete](http://msdn.microsoft.com/en-us/library/system.web.ui.page.loadcomplete.aspx)或[PreRenderComplete](http:// msdn。 microsoft.com/en-us/library/system.web.ui.page.prerendercomplete.aspx)事件? – 2012-04-24 12:35:45

+0

標題的最終調用是在一個母版頁內,我不認爲LoadComplete或PreRenderComplete是母版頁內的方法? – FirstCape 2012-04-24 12:53:07

回答

1

你的主網頁預渲染會發生,或者另一種方式將您的主頁上創建一個屬性,並直接從你的方法更新

 'On your master page 
    Private _myValue As String    'If you want the master page to remember this between postbacks use an asp:HiddenField instead of a string, or store it in the Session 
    Public Property MyProperty() As String 
     Get 
      Return _myValue 
     End Get 
     Set(ByVal value) 
      _myValue = value 
     End Set 
    End Property 

    'On your userControl or Page 
    CType(Me.Master, MyMasterPage).MyProperty 

或者另一種方法是提高泡沫事件。他們得心應手出於傳遞信息備份hirarchy對你的母版頁

RaiseBubbleEvent(Me, e) 

然後有覆蓋您OnBubbleEvent您的主頁上(只是谷歌的提高和處理泡沫事件的一些例子)

+0

謝謝,我使用了PreRender和我的答案的組合,但是您的問題最接近可能發生的其他問題。 – FirstCape 2012-04-25 07:36:40

0

我有設法使用MSDN上的一些隱藏知識的組合來解決這個問題。

http://msdn.microsoft.com/en-us/library/xxwa0ff0.aspx

這顯示瞭如何創建一個母版的引用,因此,所有我所要做的就是創建未被引用其他地方的母版的功能。然後,當按鈕觸發事件:

Dim cellSnapshot As TableCell = gvSnapshots.Rows(e.CommandArgument).Cells(0)  
Session("Snapshot") = cellSnapshot.Text  
gvSnapshots.DataBind()  
Master.PageSetTitles() 

即該PageSetTitles函數獲取Session變量,並設置內

雖然包括這個標籤:

<%@ MasterType VirtualPath="~/MasterPages/Site.Master" %> 

在頁面中。

相關問題