Showing posts with label nested. Show all posts
Showing posts with label nested. Show all posts

Wednesday, March 28, 2012

Extender control nested in 2 DataControls

Hello all!

I have problem when using The CollapsiblePanel Extender control nested in 2 dataControls.

My Code like this

1<asp:DataList id="1" DataSourceID="sds1" runat="server">2 <ItemTemplate>3 <asp:Panel id="pl1" runat="server">4 <asp:Label id="lbl1" runat="server" text="<%# Bind("NewsTitle")%>"/>5 </asp:Panel>6 <asp:LinkButton runat="server" id="lb1"/>7 <asp:Repeater id="gv1" runat="server" DataSourceID="sds2">8 <ItemTemplate>9 <asp:Label id="lbl1" runat="server" text="<%# DataBinder.Eval(Container.DataItem,"NewsTitle")%>"/>1011<atlasToolkit:CollapsiblePanelExtender ID="cpe" runat="Server">12 <atlasToolkit:CollapsiblePanelProperties13 TargetControlID="pl1"14 CollapsedSize="0"15 ExpandedSize="300"16 Collapsed="True"17 ExpandControlID="lb1"18 CollapseControlID="lb1"19 ScrollContents="True"20 TextLabelID="Label1"21 CollapsedText="Show Details..."22 ExpandedText="Hide Details"23 ImageControlID="Image1"24 ExpandDirection="Height"/>25</atlasToolkit:CollapsiblePanelExtender>262728 </ItemTemplate>29 </asp:Repeater>30 </ItemTemplate>31</asp:DataList>

Then when view this page in browser, it throw the message "Can't find Control 'pl1' for the extender 'cpe'"

How can i fix this error? Thank all!

If you move the CollapsiblePanel declaration up a level so that it sits right next to the label/panel it touches, this scenario seems to work fine for me. Have you tried that?

HiDavid!

Thank for your reply! But, i dont want move it up a level, it must be this current DataControl.

Eample, in a news site, i use datalist for display a list of new catalogue, in each news catalogue, i display some news.

My extenderControl is not Collapsible Panel, it my owner, when you click in a news Title (This News Title is in DataControl level 2 -- so DataControl level 2 have more than 1 link like that) , an Panel near this DataControl level2 and in DataControl level 1 will display some text from server (This text get by My Extender control).

So, do you know why i cant not move it up a level?

I have try Reflector and saw this error message in OnPreRender (At Microsoft.Web.UI.ExtenderBase...<T>). And this Code only support for Control in this.Page or this.NamingContainer,...

I think Atlas not good in processing it, for the best, i think this code (or another code like this ^_^) is require to find All Control that name "ID"

Control myctl =this;Control control1;while (myctl !=null){ control1 = myctl.FindControl("ID");if (control1 ==null) myctl = myctl.Parent;else myctl =null;}

Do you think so?

Thank!


oh! Im so sorry! My code:


1Control myctl =this;23Control control1;45while (myctl !=null)67{89 control1 = myctl.FindControl("ID");10if (control1 ==null) control1 = myctl.NamingContainer.FindControl("ID");11if (control1 ==null) myctl = myctl.Parent;1213else myctl =null;1415}16

Okay, there's a way to do this, but it's subject to change in the future, so it's probably best not to rely on it. But what you can do to help resolve controls that couldn't otherwise be found is to add a OnResolveTargetControlID property to your extender and then write a simple method that does the resolution for you. The OnResolveTargetControlID method is called when the extender fails to resolve the TargetControlID using its usual steps (current naming context, parent naming context, page naming context). This applies only for TargetControlID, but when it works, it's nice. :) Here's a complete sample to demonstrate the concept. Note that I've got the same basic structure you have with the extender nested deeper than the control it's targetting. Hope this helps!

<%@. Page Language="C#" %><%@. Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlastoolkit" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected override void OnLoad(EventArgs e) { base.OnLoad(e); xds1.DataFile = HttpContext.Current.Server.MapPath("~/App_Data/CarsService.xml"); } protected void ResolveTargetControlID(object sender, Microsoft.AtlasControlExtender.ResolveControlEventArgs e) { if ("p1" == e.ControlID) { e.Control = ((Control)sender).NamingContainer.NamingContainer.NamingContainer.FindControl(e.ControlID); } }</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <atlas:ScriptManager ID="sm1" runat="server"> </atlas:ScriptManager> <asp:XmlDataSource ID="xds1" runat="server"></asp:XmlDataSource> <asp:DataList ID="dl1" runat="server" DataSourceID="xds1"> <ItemTemplate> <asp:Panel ID="p1" runat="server" BackColor="Lime"> Hello </asp:Panel> <asp:Repeater ID="r1" runat="server" DataSourceID="xds1"> <ItemTemplate> Hi <atlastoolkit:DropShadowExtender ID="dse" runat="server" OnResolveTargetControlID="ResolveTargetControlID"> <atlastoolkit:DropShadowProperties TargetControlID="p1" Width="2" /> </atlastoolkit:DropShadowExtender> </ItemTemplate> </asp:Repeater> </ItemTemplate> </asp:DataList> </div> </form></body></html>

e.Control = ((Control)sender).NamingContainer.NamingContainer.NamingContainer.FindControl(e.ControlID);

^_^
So many "NamingContainer" --> so fun.
Thank you first! I will try your help!

Hello again! i've try your help and get the best! thanks you very much, with other control, not the target, there is no problem!

But i want to know: Is there an other way to do this? Some time, we dont know how many 'NamingContainer' needed!


You could build a more flexible implementation that kept searching each naming container up the chain until it reached the top (null) or found the control. But the basic idea's the same as what I showed: find the control near where you expect it to be. Glad this worked for you!

Monday, March 26, 2012

expanding accordion pane upon subcontrol getting focus

i'm setting focus to a control via javascript, but if the control is nested within an accordion pane, the panes dont expand.

is there anyway via javascript to expand the panes, apart from clicking on them with the mouse?

cheers

Pete

Hi Pete,

The easiest way will be to callset_SelectedIndex with the index of the pane you want to expand.

Thanks,
Ted

Saturday, March 24, 2012

events for asp controls nested in an atlas control

How do you go about accessing and declaring events for thosecontrols that are nested within the accordion control (for example) ?

ie.I want to have the following Sub for a txtBox that is nested within anaccordionpane? I understand to get to the control's properties you canuse the .FindControls method on the accordion pane, but how do Ideclare a control's event like below?

Protected SubtxtBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)Handles txtBox.TextChanged
...
End Sub

<atlasToolkit:AccordionPane ID="AccordionPane1" runat="server">
<Header><a href="http://links.10026.com/?link=" onclick="return false;"class="accordionLink">5. References</a></Header>
<Content>
<asp:TextBox ID="txtBox" runat="server" CssClass="txtBox" />
</Content>
</atlasToolkit:AccordionPane>

Thanks

You should be able to wire them up like you normally would through either HTML or in code.

via HTML: Just add TextChanged="txtBox_TextChanged" to your TextBox tag.

programmatically: Use FindControls to get the control and then (C#) objTextBoxRef.TextChanged += EventHandler(txtBox_TextChanged);


How would I do it in VB.Net ?

In HTML I have, for example:

<asp:TextBox ID="txtBox" OnTextChanged="txtBox_TextChanged" runat="server" CssClass="txtBox" />

on the .vb code page I then have:

Public WithEvetns txtBox as TextBox

Sub txtBox_TextChanged(ByValsender As Object, ByVal e As System.EventArgs) HandlestxtBox.TextChanged

xtBox.Text = Format(txtBoxy.Text, "currency")

End Sub

But I get the following error:

Error 1 Method 'Sub txtBoxTextChanged()' does not have thesame signature as delegate 'Delegate Sub EventHandler(sender As Object,e As System.EventArgs)'.


excuse my typos...in my last post.Actually my errors window was just not refreshing.

But still, when I run it, the textchanged event does not fire at all...


...nevermind. i did not have the attribute "AutoPostBack = True" in my tag..I hate it when I'm such a beginner...