Showing posts with label populate. Show all posts
Showing posts with label populate. Show all posts

Monday, March 26, 2012

TreeView PopulateOnDemand within AccordionPane

I have an accordion inside of an Accordion Panel, which is generated from a database. I have the treeview set to populate on demand if there are any subnodes, using the TreeNodePopulate event of the TreeView. Since the Tree is inside of the Accordion Pane, I lose design support, and have to explicitly find and cast the control from the Accordion object. Becuase of this, I lose the event handling binding to that Treeview node. I'm not sure If explicitly fetching and casting is right to begin with, so I'd rather not waste a lot of time trying to manually wire the events to the casted TreeView in codebehind if there is a better way.

Expand Category 1

The target 'ctl00$ContentPlaceHolder2$ctl01$TreeView1' for the callback could not be found or did not implement ICallbackEventHandler.

<atlastoolkit:AccordionPane ID="AccordionPane2" runat="server">
<Header>
<a href="http://links.10026.com/?link=" onclick="return false;" class="accordionLink">Panel 2</a></Header>
<Content>
<asp:TreeView ID="TreeView1" ExpandDepth="0" PopulateNodesFromClient="true" ShowLines="true"
ShowExpandCollapse="true" runat="server" OnTreeNodePopulate="TreeView1_TreeNodePopulate" />
</Content>
</atlastoolkit:AccordionPane>

TreeView tree1;

protected void Page_Load(object sender, EventArgs e)
{
tree1 = (TreeView)AccordionPane2.ContentContainer.FindControl("TreeView1");

}

protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
PopulateSubLevel(Convert.ToInt32(e.Node.Value), e.Node);
}

private void PopulateSubLevel(int parentid, TreeNode parentNode)
{
SqlConnection objConn = new SqlConnection(@dotnet.itags.org."server=SYSSIMERT01\SQLEXPRESS;Trusted_Connection=true;DATABASE=TreeViewSampleDB");
SqlCommand objCommand = new SqlCommand("select id,title,(select count(*) FROM SampleCategories WHERE parentid=sc.id) childnodecount FROM SampleCategories sc where parentID=@dotnet.itags.org.parentID", objConn);

objCommand.Parameters.Add("@dotnet.itags.org.parentID", SqlDbType.Int).Value = parentid;

SqlDataAdapter da = new SqlDataAdapter(objCommand);
DataTable dt = new DataTable();
da.Fill(dt);
PopulateNodes(dt, parentNode.ChildNodes);
}

Hi j05h,

It sounds like the event isn't being properly wired up whenever you postback. If you're creating controls dynamically (and then also their event handlers), be sure to recreate them on postback. If this doesn't help, perhaps you can provide asmall sample demonstrating the problem that I can run.

Thanks,
Ted

TreeView with checkboxes

Hi

As you know the nativ TreeView control does not populate the check state (when the attributeShowCheckBoxes="All") to his children nodes for perfomance reason.

Is it a way with Ajax and a timer to do the thing ?

I wrote this but i got flickering on the lines redraw of the TreeView

Any help ?

<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="500" />
<asp:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
</Triggers>
<ContentTemplate>
<asp:TreeView ID="TreeView1" runat="server" ShowCheckBoxes="All" ShowLines="true" OnTreeNodeCheckChanged="OnSelectPlayer">
</asp:TreeView>
<br />
<asp:Button ID="Button1" runat="server" OnClick="OnSelect" Text="Valider la sélection" Width="127px" />
</ContentTemplate>
</asp:UpdatePanel>

Thank you a lot

Hi,

Please specify <compilation debug="false"> in web.config.

In asp.net, when in debug mode, images and javascript files severed from a web resource handler won't be cached on client.

Hope this helps.

TreeView, UpdatePanel PopulateOnDemand problem

When I use a PopulateOnDemand TreeView inside an UpdatePanel - when I click on the root node to populate its immediate children, it expands with the child nodes displayed. If I then click on any of the child nodes, the root node collapses. This does not happen if not in an UpdatePanel.

Also, if I click on the root node again and then click on an immediate child to populate its children, it has the same behavior. After the root node automatically collapses, if I click on the root node again, all child nodes that were expanded will still be expanded.

Does anyone know how I can get the root node to not automatically collapse when I click on any of its descendent nodes?

The TreeView isn't supported inside an UpdatePanel, see the last bullet point on this blog and follow the UpdatePanel doc link:http://blogs.visoftinc.com/archive/2007/09/23/asp.net-ajax--updatepanel-not-working--common-problems.aspx

PopulateOnDemand PopulateNodesFromClient actually uses client script as it is.

-Damien


Thanks for the response. When you say that it uses client script, what does that mean? PopulateOnDemand seems to cause full page refreshes - even when I use EnableClientScript and PopulateNodesFromClient...


That's what PopulateNodesFromClient does:http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview.populatenodesfromclient.aspx.

The example states:"The following code example demonstrates how to use thePopulateNodesFromClient property to enable client-side population of the nodes in theTreeView control. Notice that when client-side node population is enabled, nodes are populated dynamically on the client, without the need to post back to the server."

-Damien


Thanks. My point was that it still caused a full page refresh. If it was happening on the client (using Ajax), then I wouldn't see a full page refresh. It turns out that I had to take out my TreeNodeExpanded and TreeNodeCollapsed event handlers to get rid of the full page refresh. After doing that, though, child nodes (that definitely have a parent node) have their Parent property set to null.

I am making headway though...thanks for your help.


You may want to check out this:http://steveorr.net/articles/Ajax.aspx

-Damien


Thanks. Good article. But it still does not explain why the Parent property is null on a child node. Again, this only happens with EnableClientScript, PopulateNodesFromClient and without TreeNodeExpanded and TreeNodeCollapsed event handlers. I need the Parent node for context so I can populate nodes more than 2 deep.

Wednesday, March 21, 2012

Trying to Dynamically Populate a Tab

Good Afternoon. Please forgive me for my lack of knowledge on AJAX. I am learning this because my work asked me to and I am trying work with the the TAB Control.

I have a database table that has a category field and a question field. I am able to popuplate the name of the tab when I select a disctinct category, but when I try to add something for the Content Template I receive an error. My final goal is for someone to choose one of the tabs (based off of my categories) and display a list of questions. All coming from a database table. Please look at this image and let me know what I am doing wrong.

Thanks in advance

Error

You cannot use ContentTemplate like that. ContentTemplate is the set of controls to display under the tab (body), not the label of the tab itself.

.HeaderText = "Jason" would put the text Jason in the tab.


I have already got the label name populated with the distinct cateogry. I am trying to figure out how to populate the body of each label with the appropriate questions from the database. I just put "jason" in to see if I would get the same error and I did.

In my while loop I generate the headertext of the label with CategoryNames("Category") When I try to populate the ContentTemplate with ("jason") or I try to make a call to the database to get all the questions that are associated to the category name, I get that error that I posted.

I hope I am making sense.

Thanks


This is an example of how to populate a tab dynamically. I must accept this is not very intuitive nor there is documentation about this.

==========================

Default.aspx

==========================

<%

@.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default" %>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">

<

headrunat="server"><title>Untitled Page</title>

</

head>

<

body><formid="form1"runat="server"><asp:ScriptManagerID="ScriptManager1"runat="server"/><div><ajaxToolkit:TabContainerID="TabContainer1"runat="server"></ajaxToolkit:TabContainer> </div></form>

</

body>

</

html>

============================

Default.aspx.cs

===========================

using

System;

using

System.Data;

using

System.Configuration;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

public

partialclass_Default : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

if (!this.IsPostBack)

{

int n = 3;while (n > 0)

{

AjaxControlToolkit.

TabPanel oTabPanel =new AjaxControlToolkit.TabPanel();

TabContainer1.Tabs.Add(oTabPanel);

oTabPanel.ContentTemplate = Page.LoadTemplate(

this.TemplateSourceDirectory +"\\WebUserControl.ascx");WebControl oWB =newWebControl(HtmlTextWriterTag.Div);

oTabPanel.ContentTemplate.InstantiateIn(oWB);

oTabPanel.HeaderText =

"Test" + n.ToString();

oTabPanel.SetRenderMethodDelegate(RenderA);

n--;

}

}

}

privatevoid RenderA(HtmlTextWriter output,Control container)

{

output.WriteLine((

"Position ") + ((AjaxControlToolkit.TabPanel)container).HeaderText);

}

}

=====================================

WebUserControl.ascx

=====================================

<%

@.ControlLanguage="C#"AutoEventWireup="true"CodeFile="WebUserControl.ascx.cs"Inherits="WebUserControl" %>

<

ajaxToolkit:TabPanelID="TabPanel1"runat="server">

<

ContentTemplate></ContentTemplate>

<

HeaderTemplate></HeaderTemplate>

</

ajaxToolkit:TabPanel>

=====================================

WebUserControl.ascx.cs

=====================================

using

System;

using

System.Data;

using

System.Configuration;

using

System.Collections;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

public

partialclassWebUserControl : System.Web.UI.UserControl

{

protectedvoid Page_Load(object sender,EventArgs e)

{

}

}


Thank you, This is going to sound bad, but I don't know C# so I will need to transfer this to VB.

Thanks Again, I will try first thing monday morning.


I've been trying to use this method but there seems to be some code missing -

In oTabPanel.SetRenderMethodDelegate(RenderA) what should be passed to RenderA?

Thanks