Showing posts with label click. Show all posts
Showing posts with label click. Show all posts

Wednesday, March 28, 2012

Tree view nested in Accordion taking two clicks to fire selectedNodeChanged event

I have a treeview in one of my accordion panes. When I click on a node for the first time, instead of firing the selectedNodeChanged event, it just goes through a normal postback. However the second time I click it, the event is fired correctly. Is there another event being fired that I'm not seeing?

Here's a trimed down version of the code. Thanks for any ideas. -d

<atlasToolKit:Accordion ID="navAccordion" runat="server" Height="410"
FadeTransitions="true" FramesPerSecond="40"
TransitionDuration="250"
AutoSize="None"
>

<atlasToolKit:AccordionPane ID="AccordionPane2" runat="server">
<Header><a href="http://links.10026.com/?link=" onclick="return false;" class="accordionLink">Tank Groups</a></Header>
<Content>
<asp:Panel ID="navPanel" runat="server" ScrollBars="auto" CssClass="extraPadding" BackColor="white" Width="180" Height="200">
<asp:TreeView ID="navTankGroups" OnUnload="nav_Unload" OnSelectedNodeChanged="nav_SelectedNodeChanged" runat="server" SkinID="nav" >
<Nodes>
<asp:TreeNode Text="Page 1" Value="~/page1.aspx" />
<asp:TreeNode Text="Page 2" Value="~/page2.aspx" />
</Nodes>
</asp:TreeView>
</asp:Panel>
</Content>
</atlasToolKit:AccordionPane>
</atlasToolKit:Accordion>

Here's the selectedNodeChanged routine.

Protected Sub nav_selecedNodeChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim navTankGroups As TreeView = CType(AccordionPane2.ContentContainer.FindControl("navTankGroups"), TreeView)
If Not navSchedule.SelectedNode.ValuePath = String.Empty Then
Response.Redirect(navTankGroups.SelectedNode.Value)
End If
End Sub


This appears to only be an issue on master pages. I placed the accordion in a new page and it worked fine. Anyone have an idea on why it is taking two clicks in the masterpages? -d

Hi dtamber,

I'm not sure what's going on with this... could you perhaps post the simplest possible version you have that still causes the problem?

Thanks,
Ted


Look at the source code before and after the button click, there is one of 2 possibilities.

1. someting being created dynamicly doesn't have an ID property set, in this case you'll see the treeview control in the source with different names

Like ctl03 and ctl05 in the treeview's name

2. I have fixed my postback issues by adding a hidden field to each accordion pane at page_init. I don't know why this fixes the erradic behavior, but it does.

Let me know if either of these works.

Chris


I think this needs a bump.

I just tried using an accordion in a usercontrol and added 3 panes, each containing an updatepanel containing a button.

The button click event is not fired. Adding a hidden field as Chris suggested allows the click event to fire.

Nathan


I also ran into the exact same problem. I was using a gridview inside an accordion and the events weren't firing the first attempt. If you add a control to it during OnInit then it appears to work. My assumption is that there's a problem with the RenderControls or something.

Astynax777:

I also ran into the exact same problem. I was using a gridview inside an accordion and the events weren't firing the first attempt. If you add a control to it during OnInit then it appears to work. My assumption is that there's a problem with the RenderControls or something.

Astynaxx777 - This clicking twice problem has been a real issue for me. Can you please elaborate with a small example if possible? You mean to add a control to the AccordionPane when the page loads (through the code behind)?

Your help would be greatly appreciated.


I ran into the same problem where I couldn't get a Button click event to fire off until I did whatCConchelos tried:

"2. I have fixed my postback issues by adding a hidden field to each accordion pane at page_init. I don't know why this fixes the erradic behavior, but it does."

Here's a basic example:

 
<body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div> </div> <cc1:Accordion ID="Accordion1" runat="server"> <Panes> <cc1:AccordionPane ID="AccordionPane1" runat="server"> <Header>Test1</Header> <Content> <asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton> </Content> </cc1:AccordionPane> <cc1:AccordionPane ID="AccordionPane2" runat="server"> <Header>Test2</Header> <Content> <asp:Button ID="Button1" runat="server" Text="Button" /> </Content> </cc1:AccordionPane> </Panes> </cc1:Accordion> </form></body>

The Button1 click event would not get called until I added a hidden field to the AccordionPane that contained Button1 on the Page_Init:

Private Sub Page_Init(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles MyBase.InitDim myAccordionPaneAs AccordionPaneDim myTextBoxAs New TextBox myTextBox.Visible =False myAccordionPane =MyBase.FindControl("AccordionPane2") myAccordionPane.Controls.Add(myTextBox)End Sub

I thinkAstynax777 is right - there must be something wrong with the controls inside an AccordionPane when being rendered.


Thank you very much. It should be noted that after Astynax777's suggestion I tried it with a button and I forgot to hide it, and it didn't work as expected.

Excellent example, thanks again.


Hi,

has anyone found out more about this issue? As indicated in a previous post, the issue appears to be that controls are not rendered properly the first time the accordion is loaded. When the postback occurs, the controls have a different id, and no event is fired since it cannot be hooked up to the appropriate control (since the ID has changed).

I have a slightly different problem than those posted above as the accordion I'm working with is loaded via a datasource. I cannot add controls on the init event as a temporary fix. Any idea for a workaround would be greatly appreciated until this is resolved.

Thanks


btw, this "click twice" error disappears when I have only 1 accordion control on a page. If there are two accordion controls (one is data bound, the other is not), then I have to click twice. When I only have the databound accordion, it works as intended.

The good thing is that adding the "invisible" control to each pane in the Accordion which is not databound has fixed the "click twice" error in the databound Accordion.


Ok, I think I have this problem fixed. You can see the changes I made athttp://www.codeplex.com/AtlasControlToolkit/WorkItem/View.aspx?WorkItemId=5796 . There's 2 files I uploaded for that issue. I might help you... or it might not, I have not tested it for your problem but it certainly fixed mine! Good luck.


Has anybody else tried it with the new 10660 release? For me, the event handling never worked. My accordion is completely databound and does not contain any unbound panes. Consequently, the workaround will not work for me. I've just tried it with 10660, but no change.

Dennis Doomen
Aviva Solutions


I was having all of those 'click twice' problems but in randomly places. I used Accordions on many different pages and I couldnt figure out why it worked on some pages and didnt on others. I realized that on the page that it didnt work I was doing my control loading during OnInit and on my other pages that did work it was during PageLoad. Im guessing you have to make sure that everything must be done in one or the other. If you have User Controls make sure that your logic and things are also in it's page load as well. Dont mix and match :)

Treeview & UpdatePanel - Assertion failed - cant find last / in base url

Hi,

I am using a TreeView and couple of server controls. The treeview children are dynamically added on click of a node. I have the treeview control inside an update panel. Everything works if I access the page in a normal IE window. When I try to access the same page through a modal dialog, during postback, it opens a new window. To avoid that, I've added<base target = "_self" />.

Now I'm getting another error with Atlas. On click of tree node, it says "Assertion Failed : Can't find last / in base url. If I remove the <base..> it doesn't work.

Looking for an immediate solution. I've spent almost a day in googling. But no luck yet.

Many Thanks,
Mani.

hello.

you can also try using an iframe inside your popup page (ie, put only an iframe inside your popoup window which loads the page that shows the content)...maybe it'll solve that problem.


Mani,

Add:<basetarget="_self"href="http://localhost/***/***/"runat="server"/>

because our dear js function check if u have base tag , then try to concat with href value. in your case you don't have it.

T.


what if i'm using a Master Page - i can't hard code a path in the href. Is there any way to accomplish this? Plus - even if i hard code, the paging on my grid view does not work now.

trans642:

Mani,

Add:<basetarget="_self"href="http://localhost/***/***/"runat="server"/>

because our dear js function check if u have base tag , then try to concat with href value. in your case you don't have it.

T.

GOOD THANKS !


trans642:

Mani,

Add:<basetarget="_self"href="http://localhost/***/***/"runat="server"/>

because our dear js function check if u have base tag , then try to concat with href value. in your case you don't have it.

T.

GOOD THANKS !


Try this, without hard code urlSmile
 <base target="_self" href="<%=Request.Url.OriginalString%>" />

works perfect ... Thanks.

Treeview acting strange in UpdatePanel

We are having issues with a treeview in an updatepanel with the RC release. When we click a child node, sometimes it closes other nodes at the same level. When a closed node is expanded again, it has a child node that is expanded. It looks like the treeview is mixing up an opened node with one of its child nodes. If we take it out of an update panel, it works fine, but does full postbacks at every click. Any ideas how to fix this problem?

treeview is not supported by Ajax.NET (I heard rumours about Q3 Orcas -related update)

do search in the forum


I have been searching, but didn't find much. It is just yet another ASP.NET control that isn't supported with UpdatePanels since the CTPs...

I would say treeview made troubles even in CTPs...

this control is discussed quite often here, even the post preceding yours mentions that...

http://forums.asp.net/thread/1514853.aspx


It worked fine for us before, and the menu also did. We were also able to use ReportViewers without having to do a full postback, which you have had to since the Betas.

I am really disappointed that Menu and TreeView controls are not supported in ASP.Net AJAX UpdatePanels. I have a production website that successfully uses Menu and TreeView controls in UpdatePanels using the July CTP of Atlas. Sounds like I will never be able to upgrade to the fully supported ASP.Net AJAX version. I know that the TreeView control can do an asynchronous callback for the TreeNodePopulate event, but I also need partial page postbacks for the SelectedNodeChanged event. In fact, I want PopulateNodesFromClient to be false anyway otherwise the atlas UpdateProgress control does not appear for TreeNodePopulate event asynchronous callbacks. And I extensively use Menu controls to create tabstrips in combination with a MultiView control. I hope Menu and Treeview support can still be added to the final version of ASP.Net AJAX.

Remco

Monday, March 26, 2012

Treeview inside update panel adds nodes when expanded/collapsed

Hi all,

I have something weird going on with a page with 3 treeview controls. I have them set to be expanded by default, but when I click on the collapse (or expand) image on any of the 3 treeviews, a new node is added in my second treeview with repeating data, ie:

TreeView1

1.01.11.22.02.1

TreeView2

3.03.13.2

Now, if I click on 2.0 to collapse it, a new node in TreeView2 will appear, same as 3.0. If I expand 2.0 again, or collapse another node, 3.0 is added again to TreeView2. I'm getting the data from a database table.

Here is the page behind:

protected void Page_Load(object sender, EventArgs e) {if (!Page.IsPostBack) PopulateRootLevel(); PopulateRootLevel_OD(); PopulateRootLevel_RO(); }//TreeView 1//private void PopulateRootLevel() { SqlConnection objConn =new SqlConnection("Data Source=##;Initial Catalog=##;Integrated Security=True"); SqlCommand objCommand =new SqlCommand("select *,(select count(*) FROM ccForum_Posts WHERE parentid=sc.id) childnodecount FROM ccForum_Posts sc where parentID='0' AND status='ac' AND sticky='1' ORDER BY DateTime", objConn); SqlDataAdapter da =new SqlDataAdapter(objCommand); DataTable dt =new DataTable(); da.Fill(dt); PopulateNodes(dt, TreeView1.Nodes); }private void PopulateSubLevel(int parentid, TreeNode parentNode) { SqlConnection objConn =new SqlConnection("Data Source=##;Initial Catalog=##;Integrated Security=True"); SqlCommand objCommand =new SqlCommand("select *,(select count(*) FROM ccForum_Posts WHERE parentid=sc.id) childnodecount FROM ccForum_Posts sc where parentID=@dotnet.itags.org.parentID AND status='ac' ORDER BY sticky, DateTime", 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); }protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e) { PopulateSubLevel(Int32.Parse(e.Node.Value), e.Node); }private void PopulateNodes(DataTable dt, TreeNodeCollection nodes) {foreach (DataRow drin dt.Rows) { TreeNode tn =new TreeNode(); tn.ToolTip = dr["Message"].ToString(); tn.Text = dr["subject"].ToString() +" - <span style=font-size:xx-small;> by " + dr["Author"].ToString() +" on " + dr["DateTime"].ToString() +"</span>"; tn.Value = dr["id"].ToString(); tn.NavigateUrl ="~/Post.aspx?MID=" + dr["id"].ToString() +"&PID=" + dr["PostID"].ToString(); nodes.Add(tn);//If node has child nodes, then enable on-demand populating tn.PopulateOnDemand = ((int)(dr["childnodecount"]) > 0); } }protected void Button_Command(Object sender, CommandEventArgs e) {switch (e.CommandName) {case"Expand": TreeView1.ExpandAll();break;case"Collapse": TreeView1.CollapseAll();break;default:// Do nothing.break; } }//TreeView 2//private void PopulateRootLevel_OD() { SqlConnection objConn_OD =new SqlConnection("Data Source=##;Initial Catalog=##;Integrated Security=True"); SqlCommand objCommand_OD =new SqlCommand("select *,(select count(*) FROM ccForum_Posts WHERE parentid=sc.id) childnodecount FROM ccForum_Posts sc where parentID='0' AND status='ac' AND sticky='2' ORDER BY DateTime", objConn_OD); SqlDataAdapter da_OD =new SqlDataAdapter(objCommand_OD); DataTable dt_OD =new DataTable(); da_OD.Fill(dt_OD); PopulateNodes_OD(dt_OD, TreeView2.Nodes); }private void PopulateSubLevel_OD(int parentid, TreeNode parentNode) { SqlConnection objConn =new SqlConnection("Data Source=##;Initial Catalog=##;Integrated Security=True"); SqlCommand objCommand =new SqlCommand("select *,(select count(*) FROM ccForum_Posts WHERE parentid=sc.id) childnodecount FROM ccForum_Posts sc where parentID=@dotnet.itags.org.parentID AND status='ac' ORDER BY sticky, DateTime", 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_OD(dt, parentNode.ChildNodes); }protected void TreeView2_TreeNodePopulate(object sender, TreeNodeEventArgs e) { PopulateSubLevel_OD(Int32.Parse(e.Node.Value), e.Node); }private void PopulateNodes_OD(DataTable dt, TreeNodeCollection nodes) {foreach (DataRow drin dt.Rows) { TreeNode tn =new TreeNode(); tn.ToolTip = dr["Message"].ToString(); tn.Text = dr["subject"].ToString() +" - <span style=font-size:xx-small;> by " + dr["Author"].ToString() +" on " + dr["DateTime"].ToString() +"</span>"; tn.Value = dr["id"].ToString(); tn.NavigateUrl ="~/Post.aspx?MID=" + dr["id"].ToString() +"&PID=" + dr["PostID"].ToString(); nodes.Add(tn);//If node has child nodes, then enable on-demand populating tn.PopulateOnDemand = ((int)(dr["childnodecount"]) > 0); } }protected void Button_Command_OD(Object sender, CommandEventArgs e) {switch (e.CommandName) {case"Expand": TreeView2.ExpandAll();break;case"Collapse": TreeView2.CollapseAll();break;default:// Do nothing.break; } }//TreeView 3//private void PopulateRootLevel_RO() { SqlConnection objConn =new SqlConnection("Data Source=##;Initial Catalog=##;Integrated Security=True"); SqlCommand objCommand =new SqlCommand("select *,(select count(*) FROM ccForum_Posts WHERE parentid=sc.id) childnodecount FROM ccForum_Posts sc where parentID='0' AND status='ro' ORDER BY sticky, DateTime", objConn); SqlDataAdapter da =new SqlDataAdapter(objCommand); DataTable dt =new DataTable(); da.Fill(dt); PopulateNodes_RO(dt, TreeView3.Nodes); }private void PopulateSubLevel_RO(int parentid, TreeNode parentNode) { SqlConnection objConn =new SqlConnection("Data Source=##;Initial Catalog=##;Integrated Security=True"); SqlCommand objCommand =new SqlCommand("select *,(select count(*) FROM ccForum_Posts WHERE parentid=sc.id) childnodecount FROM ccForum_Posts sc where parentID=@dotnet.itags.org.parentID ORDER BY DateTime", 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_RO(dt, parentNode.ChildNodes); }protected void TreeView3_TreeNodePopulate(object sender, TreeNodeEventArgs e) { PopulateSubLevel_RO(Int32.Parse(e.Node.Value), e.Node); }private void PopulateNodes_RO(DataTable dt, TreeNodeCollection nodes) {foreach (DataRow drin dt.Rows) { TreeNode tn =new TreeNode(); tn.ToolTip = dr["Message"].ToString(); tn.Text = dr["subject"].ToString() +" - <span style=font-size:xx-small;> by " + dr["Author"].ToString() +" on " + dr["DateTime"].ToString() +"</span>"; tn.Value = dr["id"].ToString(); tn.NavigateUrl ="~/Post.aspx?MID=" + dr["id"].ToString() +"&PID=" + dr["PostID"].ToString(); nodes.Add(tn);//If node has child nodes, then enable on-demand populating tn.PopulateOnDemand = ((int)(dr["childnodecount"]) > 0); } }protected void Button_Command_RO(Object sender, CommandEventArgs e) {switch (e.CommandName) {case"Expand": TreeView3.ExpandAll();break;case"Collapse": TreeView3.CollapseAll();break;default:// Do nothing.break; } }

And here is the control:

<%@dotnet.itags.org. Control Language="C#" AutoEventWireup="true" CodeFile="ct_forum_2.ascx.cs" Inherits="ccforum_ct_forum" %><asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <h3>TreeView1 - <asp:ImageButton ID="ExpandButton" runat="server" ImageUrl="~/images/expandall.jpg" CommandName="Expand" OnCommand="Button_Command" AlternateText="Open All Conversations" />   <asp:ImageButton ID="CollapseButton" runat="server" ImageUrl="~/images/collapseall.jpg" CommandName="Collapse" OnCommand="Button_Command" AlternateText="Close All Conversations" /></h3> <asp:TreeView ID="TreeView1" ExpandDepth="10" runat="server" OnTreeNodePopulate="TreeView1_TreeNodePopulate" ImageSet="Inbox" EnableClientScript="False" Width="100%" BackColor="White" BorderColor="#404040" LineImagesFolder="~/TreeLineImages" ShowLines="True" > <ParentNodeStyle Font-Bold="False" /> <HoverNodeStyle Font-Underline="True" /> <SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px" VerticalPadding="0px" BackColor="#404040" /> <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" /> </asp:TreeView><br /> <h3>TreeView2 - <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/expandall.jpg" CommandName="Expand" OnCommand="Button_Command_OD" AlternateText="Open All Conversations" />   <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/collapseall.jpg" CommandName="Collapse" OnCommand="Button_Command_OD" AlternateText="Close All Conversations" /></h3> <asp:TreeView ID="TreeView2" ExpandDepth="10" runat="server" OnTreeNodePopulate="TreeView2_TreeNodePopulate" ImageSet="Inbox" EnableClientScript="False" Width="100%" BackColor="White" BorderColor="#404040" LineImagesFolder="~/TreeLineImages" ShowLines="True" > <ParentNodeStyle Font-Bold="False" /> <HoverNodeStyle Font-Underline="True" /> <SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px" VerticalPadding="0px" BackColor="#404040" /> <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" /> </asp:TreeView> <br /> <h3>TreeView3 - <asp:ImageButton ID="ImageButton3" runat="server" ImageUrl="~/images/expandall.jpg" CommandName="Expand" OnCommand="Button_Command_RO" AlternateText="Open All Conversations" />   <asp:ImageButton ID="ImageButton4" runat="server" ImageUrl="~/images/collapseall.jpg" CommandName="Collapse" OnCommand="Button_Command_RO" AlternateText="Close All Conversations" /></h3> <asp:TreeView ID="TreeView3" ExpandDepth="10" runat="server" OnTreeNodePopulate="TreeView3_TreeNodePopulate" ImageSet="Inbox" EnableClientScript="False" Width="100%" BackColor="White" BorderColor="#404040" LineImagesFolder="~/TreeLineImages" ShowLines="True" > <ParentNodeStyle Font-Bold="False" /> <HoverNodeStyle Font-Underline="True" /> <SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px" VerticalPadding="0px" BackColor="#404040" /> <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" /> </asp:TreeView> </ContentTemplate></asp:UpdatePanel>

Any help will be truly appreciated.

Jose

Well, I hate to answer my own posts, but I guess stepping out of the office gave me a fresh set of eyes. My problem lied in the IsPostBack property:

protected void Page_Load(object sender, EventArgs e) {if (!Page.IsPostBack) PopulateRootLevel(); PopulateRootLevel_OD(); PopulateRootLevel_RO(); }

It should be:

if (!Page.IsPostBack) { PopulateRootLevel(); PopulateRootLevel_OD(); PopulateRootLevel_RO(); }
Hope it helps someone.

treeview inside of updatepanel = Validation of viewstate MAC failed

i have some nodes added to my treeview inside of an updatepanel and it seems to give me "

Validation of viewstate MAC failed" error each tme i click a node twice.

Nothing happens on the first time i click a node

is there some tutorial or standard thing to do with a treeview in an update panel?

It sounds very strange about asp:TreeView and asp:UpdatePanel from your description.Can you post some codes here? I'd like to test it.
I tested asp:UpdatePanel working with asp:TreeView in Ajax RC 1.0 and found it worked.
Here are my testing codes for your reference.
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TreeView ID="tv" runat="server" OnSelectedNodeChanged="tv_SelectedNodeChanged">
<Nodes>
<asp:TreeNode Text="File" Value="File"></asp:TreeNode>
<asp:TreeNode Text="Edit" Value="Edit"></asp:TreeNode>
<asp:TreeNode Text="View" Value="View"></asp:TreeNode>
</Nodes>
</asp:TreeView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress2" runat="server"
AssociatedUpdatePanelID="UpdatePanel1"
DisplayAfter="2000"
DynamicLayout="False">
<ProgressTemplate>
UpdatePanel1 is updating now!
<input type="button" id="AbortCallbackButton" value="Abort" onclick="AbortCallback()" />
</ProgressTemplate>
</asp:UpdateProgress>
<br />
This is text after the UpdatePanel and UpdateProgress controls.
<script type="text/javascript">
function AbortCallback()
{
Sys.WebForms.PageRequestManager.getInstance().abortPostBack();
}
</script>
Behind Codes:
protected void tv_SelectedNodeChanged(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(10000);
}
Wish this can help you.

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.

Saturday, March 24, 2012

Trigger wont cause a PostBack (Inside UpdatePanel)

When I click my LinkButton inside my GridView I want the page to postback and a pdf to be streamed to the browser.
It is streamed but the page dont Post so nothing is received.

What am I doing wrong here?

1Protected Sub GridView1_RowDataBound1(ByVal senderAs Object,ByVal eAs System.Web.UI.WebControls.GridViewRowEventArgs)Handles GridView1.RowDataBound23If e.Row.RowType = DataControlRowType.DataRowThen45Dim ptAs New PostBackTrigger()67pt.ControlID = e.Row.FindControl("lbtnPrintInvoice").UniqueID8UP1.Triggers.Add(pt)910End If1112End Sub

Hi,

in docs:

http://asp.net/AJAX/Documentation/Live/mref/T_System_Web_UI_PostBackTrigger.aspx

Remarks

Use thePostBackTrigger control to enable controls inside anUpdatePanel to cause a postback instead of performing an asynchronous postback.

Use theRegisterPostBackControl(Control) method of theScriptManager control to programmatically register a postback control. You can then call theUpdate() method of theUpdatePanel control when the trigger control performs a postback.

note

Programmatically addingPostBackTrigger controls is not supported.

So basically you need to use ScriptManager's RegisterPostBackControl method to do it.


Hmm I can apreciate that but how do I call my lbtnPrintInvoice inside Gridview1 thats the question... The below code doesnt work for some reason ;)

1<Triggers>2<asp:PostBackTrigger ControlID="lbtnPrintInvoice" />3</Triggers>

Gives the error:

A control with ID 'lbtnPrintInvoice' could not be found for the trigger in UpdatePanel 'UP1'.


You really read the previous reply?Big Smile

Does this help:

Protected Sub GridView1_RowDataBound1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

If e.Row.RowType = DataControlRowType.DataRow Then

ScriptManager.GetCurrent(Me).RegisterPostBackControl(e.Row.FindControl("lbtnPrintInvoice"))

End If

End Sub

-- EDIT: Fixed this reference in the code


Jeeze! I wans't aware you could actually call the scriptmanager like that since mine is in the masterpage I never thought I could adress it directly

Thanks a bunch for the solution though for people that might want the complete solution I added the page reference in the below code as well.

1Protected Sub GridView1_RowDataBound1(ByVal senderAs Object,ByVal eAs System.Web.UI.WebControls.GridViewRowEventArgs)Handles GridView1.RowDataBound23If e.Row.RowType = DataControlRowType.DataRowThen4ScriptManager.GetCurrent(Me).RegisterPostBackControl(e.Row.FindControl("lbtnPrintInvoice"))5End If67End Sub

Oh and I also tried to do it in RowCreated, never would have worked out.


ScriptManager has good utility methods. It's worth to know about them. I edited & corrected the code. Made a typo as I typed directly to the post.

Triggering PopupControlExtender from button click

I've got a simple scenario: I'm using a text box with a PopupControlExtender to display a calendar. Works great, but not the most intuitive way to bring up the calendar. I'd like to add an image button to the right of the text box that could ALSO trigger the opening of the calendar, in addition to the normal click on the text box.

I've tried using a call to this as the OnClientClick property, but nothing happens:

function OnButtonClick(){ var behavior = $find('pce'); behavior.showPopup();}

I'd appreciate any assistance on what seems like itshould beso obvious!

-- Jim --

what about using the AJAX toolkit's built-in calendar extender?

Triggering modal popup with javascript causes popup controls to be disabled and popup disa

I'm triggering a modal popup to popup in a javascript:

document.getElementById('ModalPopupTrigger').click();

The element specified is set as the TargetControl for the modal popup.

The popup does popup but the control's on it can't be used and the popup disappears automatically after ~ 2 seconds...

Any clues as to what's going on here?

Define the BehaviorID property of your ModalPopupExtender control and use its show() method. For example (taken from the toolkit sample):

<ajaxToolkit:ModalPopupExtender runat="server" ID="programmaticModalPopup" BehaviorID="programmaticModalPopupBehavior" TargetControlID="hiddenTargetControlForModalPopup" PopupControlID="programmaticPopup"
BackgroundCssClass="modalBackground" DropShadow="True" PopupDragHandleControlID="programmaticPopupDragHandle" >

Given that declaration, you can show the popup by calling $find('programmaticModalPopupBehavior').show()


Ok, both methods actually work. The problem turned out to be that the javascript was triggered by a link button in an update panel which was causing the panel with the popup to refresh. Changed it to a label and it works fine...

Wednesday, March 21, 2012

trouble with dynamic tabs

Hi I am having two issues with trying to create dynamic tabs with the AjaxControlToolkit Tabs Control. First when I click the button1 to create the tab it creates 2 tabs and if I hit the button again I get the error "Specified argument was out of the range of valid values"

My aspx is

<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" EnableEventValidation="false" %
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<script type="text/javascript">

</script>
<div>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Add Tab" /><br />
<br />
<br />
<br />
<ajaxToolkit:tabcontainer id="TabContainer1" runat="server" activetabindex="0">
</ajaxToolkit:tabcontainer></div>
</form>
</body>
</html>


My vb code is:

PartialClass _DefaultInherits System.Web.UI.PageProtected Sub Button1_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Button1.ClickDim tabAs AjaxControlToolkit.TabPanel =New AjaxControlToolkit.TabPanel()Dim frame1As System.Web.UI.HtmlControls.HtmlGenericControl =New System.Web.UI.HtmlControls.HtmlGenericControl("iframe") frame1.Attributes("src") ="http://search.msn.com" frame1.Attributes("frameborder") ="0" frame1.Attributes("width") ="800" frame1.Attributes("height") ="600" frame1.Attributes("scrolling") ="auto" tab.Controls.Add(frame1) tab.Width ="800" tab.Height ="600" tab.HeaderText ="Tab " TabContainer1.Tabs.Add(tab) TabContainer1.ActiveTab = tabEnd SubEnd Class
Any help would be greatly appreciated.

Hi,

This is a common problem when working with dynamic controls.

The problem is that dynamic controls don't exist on the second request before the Button1_Click method fires. You need to recreate it in Page_Init rather than Button_Click.

Please refer to this documentation for more information:

1. Why do I have to recreate dynamic controls every time? /Why dynamic controls are disappeared on PostBack?

Whenever a request comes, a new instance of the page that isbeing requested is created to serve the request even it's a PostBack. Allcontrols on the page are reinitialized, and there state can be restored fromthe ViewState in a later phase.

The dynamic controls have to be recreated again and added tothe control hierarchy. Otherwise, they won't exist in the page.

Please be careful with when to create dynamic controls. Inorder to keep their state, they have to be created before the LoadViewStatephase. Page_Init as well as Page_Load methods are options available.

For more information about this topic, please refer to thisarticle:

Creating Dynamic Data Entry User Interfaces[http://msdn2.microsoft.com/en-us/library/aa479330.aspx ]

Hope this helps.