Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
440
Cannot refer to object inside UpdatePanel from server
posted

I have a ASP.NET Web Application using VB.NET in Visual Studio 2010 with 2012 Volume 1 (CLR 4.0). I have a button inside an UpdatePanel in an item template, but I cannot refer to it in the server code. The page source is:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="SimpleExample.aspx.vb"
    Inherits="DataPAEnterpriseWeb.SimpleExample" %>
 
<%@ Register Assembly="Infragistics4.Web.v12.1, Version=12.1.20121.1005, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
    Namespace="Infragistics.Web.UI.NavigationControls" TagPrefix="ig" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <ig:WebExplorerBar ID="WebExplorerBar1" runat="server" Width="250px">
            <Groups>
                <ig:ExplorerBarGroup GroupContentsHeight="" Text="Categories" Expanded="True">
                    <Items>
                        <ig:ExplorerBarItem Text="Item" TemplateId="TreeViewTemplate">
                            <Template>
                                <asp:UpdatePanel ID="TreeViewUpdatePanel" runat="server">
                                    <ContentTemplate>
                                        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
                                    </ContentTemplate>
                                </asp:UpdatePanel>
                            </Template>
                        </ig:ExplorerBarItem>
                    </Items>
                </ig:ExplorerBarGroup>
            </Groups>
            <AutoPostBackFlags ItemClick="Off" />
        </ig:WebExplorerBar>
    </div>
    </form>
</body>
</html>

However, The following:

 

Public Class SimpleExample
  Inherits System.Web.UI.Page

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Button1.Text = "OK"
  End Sub

End Class

Gives the following error "'Button1' is not declared. It may be inaccessible due to its protection level.".

 

 

Parents
No Data
Reply
  • 18204
    Verified Answer
    Offline posted

    Hello DataPA,


    For our templated controls, you will need to programatically assign the variables to access them.  Since templates may be used more than once, the controls in them cannot be defined at runtime.  Please see the following code snippet for a demonstration of how to do this:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim upTemplate As UpdatePanel = Me.WebExplorerBar1.Groups(0).Items(0).FindControl("TreeViewUpdatePanel")
        Dim button As Button = Nothing

        If Not upTemplate Is Nothing Then
            button = upTemplate.FindControl("Button1")
        End If

        If Not button Is Nothing Then
            button.Text = "OK"
        End If
    End Sub

    Please let me know if you need further assistance with this issue and I'll be glad to help.

Children