|
Rank: Advanced Member Groups: Member
Joined: 3/18/2008 Posts: 41
|
Hi. I have a CustomItem which contains a asp textbox. I want to programmatically find this textbox in order to add attributes. In most server controls the function is typically named FindControl(Control control). How can I find the control in the CustomItem? The textbox I want to find is inside
Code: C#
myMenu.Items[0].CustomItem
Thanks HT
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
I believe you can do that with:
myMenu.Items[0].CustomItemInstance.FindControl(...);
CustomItemInstance would only exist after you have called DataBind. CustomItem is the template, CustomItemInstance is the instance that is created based on the template (similar to ItemTemplate and GridItem for DataGrid control).
Thanks
|
|
Rank: Advanced Member Groups: Member
Joined: 3/18/2008 Posts: 41
|
Thanks for your reply. I get an error. Here is my code:
Code: C#
Button bSearch = ((Button)myMenu.Items[0].CustomItemInstance.FindControl("btnSearch"));
Error: "Object reference not set to an instance of an object." at myMenu.Items[0].CustomItemInstance. CustomItemInstance is null. But I know there is a CustomItem at myMenu.Items[0]. I'm adding items manually, not by setting the DataSource property. Can this be the reason? Is yes, how can I solve it? HT
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
I understand that you add menu items manually, but how do you add CustomItem manually? Do you do it by setting the menu item's CustomItemID? If that is the case, then you won't get CustomItemInstance. CustomItemInstance is strictly for MenuItem.CustomItem. When you do it with CustomItemID, you will need to call FindControl on the CustomItem object that you orginally created. The menu does not keep track of this object because it did not create it.
Thanks
|
|
Rank: Advanced Member Groups: Member
Joined: 3/18/2008 Posts: 41
|
Sorry, I forgot som code. I have hardcoded the content of the CustomItem. Here is the hardcoded code for myMenu.Items[0]:
Code: HTML/ASPX
<eo:MenuItem Width="250">
<CustomItem>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" onclick="btnSearch_Click"/>
</CustomItem>
</eo:MenuItem>
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
We have verified that CustomItemInstance is not ready until at late stage of the page cycle. So it is not there yet during Page_Load. We have post a new build that would ready it when you request it. That should fix the issue for you. Please see your private message for download location.
Thanks!
|
|
Rank: Advanced Member Groups: Member
Joined: 10/21/2009 Posts: 39
|
I have a Menu named Menu1 with a CustomItem for one of its MenuItems. Inside the CustomItem I have a LinkButton. How can I access this LinkButton to change its Width in the Menu1_PreRender method.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi David,
I believe our first reply to the original question has already answered your question. Please let us know if you still have any questions.
Thanks!
|
|
Rank: Advanced Member Groups: Member
Joined: 10/21/2009 Posts: 39
|
myMenu.Items[0].CustomItemInstance is null for all items in myMenu. The menu is created statically in the designer so I never call databind. I am trying to access the custom control in the Menu1_PreRender method. Please advise.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
In that case you just replace myMenu.Items[0].CustomItemInstance with your CustomItem control, for example, "CustomItem1". The idea is you always get your control by calling FindControl on the containing CustomItem control.
Thanks!
|
|