views:

347

answers:

1

I need to add a trigger for two buttons in DataGrid Template columns. I have found a couple postings saying to put the code in the code-behind using the UniqueID.

Something isn't right with my logic (or maybe it isn't in the right place). I am getting "Object reference not set to an instance of an object" error when I run it.

I am getting this on my "gridSelectTrigger.ControlID = btnSessionSelect.UniqueID" statement.

Does this logic need to be in an "ItemDataBound" event? Or is my logic wrong?

<%@ Page Title="Admin Session Folders" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="AdminAddEditReleaseAndFiles.aspx.vb" Inherits="AdminAddEditReleaseAndFiles" Theme="Standard" %>



            

<asp:Panel ID="pnlEditTopic" runat="server" CssClass="modalPopupEditTopic" Style="display: none;" >
    <table cellspacing="0" class="borderTable0" width="100%" style="">
        <tr style="height:4px">
            <td colspan="6" align="center">
                <asp:ImageButton ID="btnAddTopic" runat="server" AlternateText="Add Topic" 
                    ImageUrl="~/App_Themes/Common/images/BtnApply.jpg" Height="28px">
                </asp:ImageButton>
                <asp:ImageButton ID="btnUpdateTopic" runat="server" AlternateText="Update Topic" 
                    ImageUrl="~/App_Themes/Common/images/BtnApply.jpg" Height="28px">
                </asp:ImageButton>
                <asp:ImageButton ID="btnDeleteTopic" runat="server" AlternateText="Delete Topic" 
                    ImageUrl="~/App_Themes/Common/images/BtnDelete.jpg" Height="28px">
                </asp:ImageButton>
                <asp:ImageButton ID="btnEditTopicClose" runat="server" AlternateText="Close Edit Topic Popup" 
                    ImageUrl="~/App_Themes/Common/images/BtnCancel.jpg" Height="28px">
                </asp:ImageButton>
            </td>
        </tr>  
    </table>
 </asp:Panel>

 </ContentTemplate>
 </asp:UpdatePanel>

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

 If Not (IsPostBack) Then
  Dim MainContent As ContentPlaceHolder = TryCast(Page.Master.FindControl("ContentPlaceHolder1"), ContentPlaceHolder)
  Dim UpdatePanelSessions As UpdatePanel = TryCast(MainContent.FindControl("UpdatePanelSessions"), UpdatePanel)
  Dim btnSessionSelect As Button = TryCast(UpdatePanelSessions.FindControl("btnSessionSelect"), Button)
  Dim btnSessionDetail As Button = TryCast(UpdatePanelSessions.FindControl("btnSessionDetail"), Button)
  Dim gridSelectTrigger As AsyncPostBackTrigger = New AsyncPostBackTrigger
  Dim gridDetailTrigger As AsyncPostBackTrigger = New AsyncPostBackTrigger
  gridSelectTrigger.ControlID = btnSessionSelect.UniqueID
  gridSelectTrigger.EventName = "Click"
  UpdatePanelSessions.Triggers.Add(gridSelectTrigger)
  gridDetailTrigger.ControlID = btnSessionDetail.UniqueID
  gridDetailTrigger.EventName = "Click"
  UpdatePanelSessions.Triggers.Add(gridDetailTrigger)
    End If

End Sub

Thank you, James

A: 

Got it. The update panel needed children as triggers set to true.

James