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
Hi Nick,
I apologize for not responding sooner. I followed the steps you suggested and was unable to reproduce the behavior you're describing. I added your code and markup to my sample and placed a breakpoint in tvCategories_NodeClick event. I added some test data for the nodes and then ran it. When I clicked on one of the nodes, the tvCategories_NodeClick event fired for me. It may help for you to add the following property to the WebDataTree even though I did not require it: OnNodeClick="tvCategories_NodeClick"
I have attached the sample project I used to test this. Please test this project on your PC; whether or not it works correctly may help indicate the nature of this problem.
If the project does not work correctly, this indicates either a problem possibly specific to your environment, or a difference in the DLL versions we are using. My test was performed with IE8 and using version 12.1.20121.1005 in NetAdvantage for ASP.NET 2012 Volume 1.
If the project does show the product feature working correctly, this indicates a possible problem in the code of your application. It will help if you can provide a small, isolated sample application that demonstrates the behavior you are seeing.
Or, if this sample project is not an accurate demonstration of what you're trying to do, please feel free to modify it and send it back, or send a small sample project of your own if you have one.
Please let me know if I can provide any further assistance.
Fantastic Michael, that worked. Thanks again for all your help, much appreciated.
Nick
After doing some testing with this, it seems that the issue actually lies in WebDataTree being in the UpdatePanel. First, I moved just the Tree outside of the ExplorerBar as you mentioned and it was working correctly. I then tried wrapping that Tree in the UpdatePanel and this reproduced the issue.
Our Aikido controls (WebDataTree, WebDataMenu, WebDataGrid, etc...) have AJAX functionality built into them. If you don't need the UpdatePanel around the Tree for other reasons, I recommend removing it. I've re-attached a sample that shows how I've set this up.
I'm still requesting to submit this as a development issue since I would expect this to work even when using an UpdatePanel.
Please let me know if you need further assistance with this.
Thanks for the help so far. I managed to get the event firing after working out the difference in my code (I had a ScriptManager rather than a WebScriptManager). Unfortunately I now have another problem!
In the event, I am changing the ContentURL of a WebSplitter panel. When the treeview was not inside the WebExplorer bar this worked fine, but now although I can see the event firing, IsPostBack is true and I can see the ContentURL being changed in my code, it never updates the content of the panel in the page.
I've replicated the problem in your example and attached it here. Thanks again for the help!!!
yeah sorry, been very busy the last week. Tried your project, and it works fine. Haven't had the chance to work out what's different, but will do next week. Will let you know how I get on, thanks for the help so far.
Please let me know how I can assist you further with this issue.