Welcome Guest Search | Active Topics | Sign In | Register

Finding a textbox control within a CustomItem Options
HT
Posted: Tuesday, June 24, 2008 12:12:28 PM
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
eo_support
Posted: Tuesday, June 24, 2008 12:16:06 PM
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

HT
Posted: Thursday, June 26, 2008 1:53:27 PM
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
eo_support
Posted: Thursday, June 26, 2008 2:00:49 PM
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
HT
Posted: Thursday, June 26, 2008 2:10:57 PM
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>
eo_support
Posted: Thursday, June 26, 2008 9:45:44 PM
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!
David
Posted: Saturday, July 24, 2010 5:34:26 PM
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.
eo_support
Posted: Monday, July 26, 2010 9:20:48 AM
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!
David
Posted: Tuesday, July 27, 2010 3:38:15 PM
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.
eo_support
Posted: Tuesday, July 27, 2010 3:54:22 PM
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!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.