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.".
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 IfEnd Sub
Please let me know if you need further assistance with this issue and I'll be glad to help.
Hi Michael,
Any answer to my follow up question?
ThanksNick
Great stuff Michael, thanks, that worked a treat.
However, I now have another issue. The object I was adding was actually a WebDataTree (I used a button for a simple example). I need to respond to the NodeClick event of the WebDataTree, but now it is inside the ExplorerBar the event doesn't fire.
My code in the server code is as follows;
Public Class _default1 Inherits System.Web.UI.Page Dim WithEvents tvCategories As WebDataTree 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") tvCategories = upTemplate.FindControl("tvCategories") End Sub Private Sub tvCategories_NodeClick(sender As Object, e As Infragistics.Web.UI.NavigationControls.DataTreeNodeClickEventArgs) Handles tvCategories.NodeClick .... End Sub
and the relevant section of the page Markup is ...
<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> <ig:WebDataTree ID="tvCategories" runat="server" AnimationDuration="300" AnimationEquationType="EaseInOut" EnableHotTracking="True" Height="100%" SelectionType="Single" Width="100%" EnableExpandOnClick="True" StyleSetName="Office2010Blue"> <AutoPostBackFlags NodeClick="On" /> </ig:WebDataTree> </ContentTemplate> </asp:UpdatePanel> </Template> </ig:ExplorerBarItem> </Items> </ig:ExplorerBarGroup> </Groups> <AutoPostBackFlags ItemClick="Off" /> </ig:WebExplorerBar>
Thanks very much again.Nick