Showing posts with label dynamically. Show all posts
Showing posts with label dynamically. Show all posts

Wednesday, March 28, 2012

Accordian - Dynamic addition/subtraction of panels?

I want to create an accordian at page load and dynamically add a number of panels with varying content at that time..any thoughts and optimally psuedocode on how to do this?Hi Mike,

You can do it just like other controls. Here's a small example:

<%@. 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"> /// <summary> /// Dynamically create our accordion panes /// </summary> protected override void OnLoad(EventArgs e) { base.OnLoad(e); AccordionPane pane1 = new AccordionPane(); pane1.HeaderContainer.Controls.Add(new LiteralControl("Pane 1")); pane1.ContentContainer.Controls.Add(new LiteralControl("Pane 2")); MyAccordion.Controls.Add(pane1); AccordionPane pane2 = new AccordionPane(); pane2.HeaderContainer.Controls.Add(new LiteralControl("Pane 2")); pane2.ContentContainer.Controls.Add(new LiteralControl("Content 2")); MyAccordion.Controls.Add(pane2); }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Accordion Demo</title> <style> .accordionHeader { border: 1px solid #2F4F4F; color: white; background-color: #2E4d7B; font-family: Arial, Sans-Serif; font-size: 12px; font-weight: bold; padding: 5px; margin-top: 5px; cursor: pointer; } .accordionContent { background-color: #D3DEEF; border: 1px dashed #2F4F4F; border-top: none; padding: 5px; padding-top: 10px; } </style></head><body><form runat="server"><div> <atlas:ScriptManager ID="Scripts" runat="server" /> <atlasToolkit:Accordion ID="MyAccordion" runat="server" SelectedIndex="0" HeaderCssClass="accordionHeader" ContentCssClass="accordionContent" FadeTransitions="true" FramesPerSecond="40" TransitionDuration="250" AutoSize="None"> </atlasToolkit:Accordion></div></form></body></html>
Thanks,
Ted

I think the code to add AccordinePane to Accordin is changed. the previous code didnt work for me.

// import Atlas Controlkit.

using System.Web.UI.HtmlControls;
using AtlasControlToolkit;

//Create a Atlas Accordion instance.
Accordion aAccord = new Accordion();


// Create AccordionPane instance.

AccordionPane accordPane = new AccordionPane();

// create your Header panel( the title of each Pane). and your component to each pane container.
// add Header Panel and Container panel, the panel which which will collape and open.

accordPane.HeaderContainer.Controls.Add( headerPanel );
accordPane.ContentContainer.Controls.Add( collapsePanel );

// add accordPane to Accordin instance.
aAccord.Panes.Add(accordPane);


// you can add as many AccordPanes as you want.


// Add Accordin object to the Panel.
myPanel.Controls.Add( aAccord );

Kishore.


Hi Kishore,

Yes - in response to user feedback we've hidden theControls collection and replaced it with the easier to useAccordionPane-onlyPanes collection.

Thanks,
Ted

Is there a way to add an unknown number of AccordionPanes? I'm trying to do thing:

List<string> addresses =newList<string>();
addresses.Add("123 Main St, Phoenix, AZ, 85041");
addresses.Add("658 Alta Vista Rd, Phoenix, AZ, 85041");int name =1;
foreach (string sin addresses)
{
AccordionPane pane =newAccordionPane();
pane.HeaderContainer.Controls.Add(newLiteralControl(s));

pane.Width =

300;
pane.ID ="pane" + name;
Accordion1.Controls.Add(pane);//it doesn't add the right pane because it's named wrong. What should I change?
name++;
}

Thanks!


And I can add the code in VB:

This is in AJAX.aspx (for example):

<ajaxToolkit:AccordionID="aDynamicky"runat="server">

<Panes>

</Panes>

</

ajaxToolkit:Accordion>

And following is in code behind AJAX.aspx.vb:

Imports AjaxControlToolkit

Partial

Class AJAXInherits System.Web.UI.PageProtectedSub aDynamicky_PreRender(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles aDynamicky.PreRenderDim panel1As AccordionPane =New AccordionPane

panel1.HeaderContainer.Controls.Add(

New LiteralControl("This is a header of 01."))

panel1.ContentContainer.Controls.Add(

New LiteralControl("And here is the content of 01."))

aDynamicky.Panes.Add(panel1)

Dim panel2As AccordionPane =New AccordionPane

panel2.HeaderContainer.Controls.Add(

New LiteralControl("This is a header of 02."))

panel2.ContentContainer.Controls.Add(

New LiteralControl("And here is the content of 02."))

aDynamicky.Panes.Add(panel2)

EndSub

End

Class

Of course, you can format your panels via CSS.

Accessing values from dynamically created controls

Hi. I'm writing a web application that uses Atlas todynamically create controls in a specific section of a web page. I have 2 update panels. One of them contains a DropDownList. The other one will contain thedynamically created controls. The controls are created in the SelectedIndexChanged event of the DropDownList, and I coded that in the server side. All those controls are arranged in a table server control, which is also created in the SelectedIndexChanged event. The page also has a Button server control that will allow me to start processing the values entered by the user in the created controls. Of course this processing will be done in the server side. This button is not part of either update panel.

Now, the problem is that when I try to get the values of the controls in the Button Click server event, using the table.FindControl() function, I see that the table itself is null, so I cannot access any control value. I think the problem has to do with the fact that the table and its controls are created in the update panel, and for some reason everything created there is not available for my Button Click server event.

How can I solve this scenario?

Thanks,

Julio

Modifying the controls colletion during a postback is generally not a good idea in ASP.NET. Additionally, dynamically added controls will not persist through viewstate so you'll have to re-create and add them to the container on each postback.

Instead of adding/removing controls, I suggest you use the "Visible" property of the control. You can set the control.Visible=false, which will prevent it from rendering down to the client.

Hope this helps,

-Tony


Thanks a lot Tony. The problem is that the user can choose 25 different elements in my combobox, and each element will require to create/show from 1 to 20 new controls on the dynamic section of the page. So if I take your advise and just put all possible controls on the page on design view, hidding or showing them asappropriate, wouldn't it be too much overhead for my page?

Julio


Julio,

Any way you choose is going to require quite a bit of code on your end to determine when to show/hide or create/destroy controls. You are correct in that should you choose to instantiate all controls on the page load, it will indeed add extra overhead.

To acheive the results you are looking for, you'll need to test for which item is selected, and fill the update panel accordingly. The earlier this happens in the page lifecycle the better off you are. The one problem you might encounter is that replacing a control on the fly like this, could cause viewstate errors since the control which saved its viewstate in the previous response, has now been replaced with a completely different control.

We've actually built the behavior you're looking for directly into the Infragistics WebTab. It provides LoadOnDemand behavior though an AJAX mechanism. Using a Tab Interface also speeds up the development since you can separate your content into individual tabs, displaying only the relevant tab. In most cases the performance overhead incurred is well worth the development time saved. Of course, you'd need to make that call based on your own project requirements.

Hope this helps,
-Tony


Hi Tony. You are completely right. I have just found that viewstate error you mention. I have tried to control that error, but I just keep getting errors when adding/removing controls. I would like to try using Infragistics WebTab, as our company has full licenses for the NetAdvantage suite. Could you please show me a small example of how could I achieve this behavior with the WebTab and the LoadOnDemand behavior? Or maybe give me a link to an example? I would reallyappreciate it.

Thanks a lot for your help,

Julio


Hi Julio,

You'll need to getNetAdvantage 2006 Volume 2 if you don't already have it. On the WebTab, set AsyncMode=On, and AsyncOptions.EnableLoadOnDemand=True. Next, using the interactive design surface, simply drag and drop your content into the desired Tab pane. You can even switch between tabs by clicking the desired tab on the design-surface. The WebTab has UpdatePanel-like behavior built directly into it, so postbacks will automatically be turned into AJAX callbacks. The LoadOnDemand behavior will also enable the initial page load to contain only the content for the selected tab, all other tab content will be dynamically retrieved as necessary.

Hope this helps,
-Tony


Hi Tony. It seems likeUltraWebTabAJAX features won't help me. Theasync behavior I'm looking for starts outside the tab control, but not in the tabs itself. My UltraWebTab has 25 tabs inside it. I also have a dropdownlist which is outside my UltraWebTab. Now, without any AJAX behavior, what my page does is that, when you select an element in the dropdownlist I hide all the tabs except for the one that is related to the selected value on the dropdownlist. This of course causes a full roundtrip to the server.

So, what I'd like to happen is that, when I change my selection on the dropdownlist, all the not related tabs just become invisible, but with no roundtrip. I enabled all the async options you mentioned, but I thing they are mostly targeted for the scenarios where the user navigates between tabs, and no with my particular scenario. So I just thought I could solve this by adding an Atlas UpdatePanel and putting the UltraWebTab inside it. I also added a trigger to the panel so that any time the dropdownlist change its value, the updatePanel would update its contents.

Here is the code for my DropDownList:

<table>

<tr>

<tdstyle="width: 3px"valign="top">

<asp:DropDownListID="MyDropDownList"runat="server"AutoPostBack="True"DataSourceID="MyDataSource"DataTextField="Description"DataValueField="Id"></asp:DropDownList><asp:ObjectDataSourceID="MyDataSource"runat="server"SelectMethod="GetMyItems"TypeName="MyProduct.MyClass"></asp:ObjectDataSource></td>

</tr>

</table>

...And this is the code for the UltraWebTab and the UpdatePanel:

<table>

<tr><tdstyle="width: 239px; height: 101%;"valign="top"><atlas:UpdatePanelID="Up1"runat="server"Mode="conditional"><ContentTemplate><igtab:UltraWebTabID="MyUltraWebTab"runat="server"BorderColor="#949878"BorderStyle="Solid"BorderWidth="1px"ThreeDEffect="False"SelectedTab="16"AsyncMode="On"><DefaultTabStyleBackColor="#FEFCFD"Font-Names="Microsoft Sans Serif"Font-Size="8pt"ForeColor="Black"Height="22px"><PaddingTop="2px"/></DefaultTabStyle><Tabs>

<!--Here comes my Tabs and controls -->

</Tabs><RoundedImageFillStyle="LeftMergedWithCenter"HoverImage="[ig_tab_winXP2.gif]"LeftSideWidth="7"NormalImage="[ig_tab_winXP3.gif]"RightSideWidth="6"SelectedImage="[ig_tab_winXP1.gif]"ShiftOfImages="2"/><SelectedTabStyle><PaddingBottom="2px"/></SelectedTabStyle><BorderDetailsColorBottom="90, 120, 160"ColorRight="90, 120, 160"/><AsyncOptionsEnableLoadOnDemand="True"/></igtab:UltraWebTab></ContentTemplate><Triggers><atlas:ControlValueTriggerControlID="MyDropDownList"PropertyName="SelectedValue"/></Triggers></atlas:UpdatePanel></td>

</tr>

But now I'm just getting an "Unknown Error" popup window every time I change my selection in the dropdownlist. It seems like any combination of UltraWebTab and UpdatePanel just does not work. I have already written Atlas apps with my current installation (June CTP) and they work fine until I add an UltraWebTab. All Atlas configurations in the web.config and the script manager are on place, so it should work.

Is there a known compability issue between UltraWebTab and UpdatePanel? If it is, is there any way I could achieve my desired behavior with UltraWebTab async and loadOnDemand options?

Thanks a lot,

Julio


Hi Julio,

You should contact Infragistics Developer Support and provide them the details above. A hotfix was made available on Friday, July 28th which may address this issue.

-Tony

Accessing Controls embedded in panel within hoverMenuExtender

I have a Panel with labels inside. I need to add more labls dynamically on run time depending what is returned from a database. This panel is referenced by the hoverMenuExtender. The problem is, is that I cant access any of the panels ID's in the code behind. You can see from the code below in lines 23-42. I need to add more labels there dynmically depending on what is returned from the database on Page_Load.
  
1 <asp:DataList ID="DataList1" runat="server" AlternatingItemStyle-BackColor="ivory"2 CellPadding="5" RepeatColumns="5" Width="92%">3 <HeaderTemplate>4<!-- <table id="RepeaterTable1" border="0">5 <tr>6 <th>ID</th>-->7 <b>8 <asp:Label ID="lblTime2" runat="server"></asp:Label></b>9<!--<th>IP</th>-->10 </tr>11 </HeaderTemplate>12 <ItemTemplate>13<!-- <tr>14 <td><%#Container.DataItem("ID")%></td>-->15 <asp:Panel runat="server" ID="panelMain">16 <asp:Image ID="Image1" runat="server" Height="21px" ImageUrl='<%#Container.DataItem("imgName")%>'17 Width="21px" />18    19<%#Container.DataItem("ServerName")%>20 </asp:Panel>2122 <asp:Panel ID="hovPanel" runat="server" BackColor="black" Width="300px" ForeColor="white">23 <asp:Image ID="hovImage" runat="server" Height="21px" ImageUrl='<%#Container.DataItem("hovIconPing")%>'24 Width="21px" />  <asp:Label runat="server" ID="hovDisk" text='<%#Container.DataItem("hovPing")%>' />25 <br />26 <asp:Image ID="Image3" runat="server" Height="21px" ImageUrl='<%#Container.DataItem("hovIconPhy")%>'27 Width="21px" />  <asp:Label runat="server" ID="Label2" text='<%#Container.DataItem("hovPhy")%>' />   <asp:Label runat="server" ID="Label3" text='<%#Container.DataItem("hovPerPhy")%>' />28 <br />29 <asp:Image ID="Image4" runat="server" Height="21px" ImageUrl='<%#Container.DataItem("hovIconVirt")%>'30 Width="21px" />  <asp:Label runat="server" ID="Label4" text='<%#Container.DataItem("hovVirt")%>' />   <asp:Label runat="server" ID="Label5" text='<%#Container.DataItem("hovPerVirt")%>' />31 <br />32 <asp:Image ID="Image2" runat="server" Height="21px" ImageUrl='<%#Container.DataItem("hovIconDiskOne")%>'33 Width="21px" />  <asp:Label runat="server" ID="Label1" text='<%#Container.DataItem("hovDiskOne")%>' />   <asp:Label runat="server" ID="Label10" text='<%#Container.DataItem("hovPerOne")%>' />34 <br />35 <asp:Image ID="Image5" runat="server" Height="21px" ImageUrl='<%#Container.DataItem("hovIconDiskTwo")%>'36 Width="21px" />  <asp:Label runat="server" ID="Label6" text='<%#Container.DataItem("hovDiskTwo")%>' />   <asp:Label runat="server" ID="Label9" text='<%#Container.DataItem("hovPerTwo")%>' />37 <br />38 <asp:Image ID="Image6" runat="server" Height="21px" ImageUrl='<%#Container.DataItem("hovIconDiskThree")%>'39 Width="21px" />  <asp:Label runat="server" ID="Label7" text='<%#Container.DataItem("hovDiskThree")%>' />   <asp:Label runat="server" ID="Label8" text='<%#Container.DataItem("hovPerThree")%>' />40 <br />41 <asp:Image ID="Image7" runat="server" Height="21px" ImageUrl='<%#Container.DataItem("hovIconCPU")%>'42 Width="21px" />  <asp:Label runat="server" ID="Label11" text='<%#Container.DataItem("hovCPU")%>' />   <asp:Label runat="server" ID="Label12" text='<%#Container.DataItem("CPUPer")%>' />4344 </asp:Panel>45 <ajaxToolkit:RoundedCornersExtender ID="rnd" runat="server" TargetControlID="hovPanel" Radius="6" />46 <ajaxToolkit:HoverMenuExtender ID="HoverMenuExtender1" runat="server" PopupControlID="hovPanel" TargetControlID="PanelMain" OffsetX="0" OffsetY="0" PopDelay="50" PopupPosition="bottom">47 </ajaxToolkit:HoverMenuExtender>4849 </ItemTemplate>50 <FooterTemplate>51<!--</table>-->52 </FooterTemplate>53 </asp:DataList>

And you say that you *can* reference the panel Id's when you're not using an UpdatePanel?I've frequently had trouble finding controls when they're part of a collection inside another control, even previous to ajax extensions work.

Typically, I've resorted to iterating over the items collection of the datalist to do it, using the syntax DataList1.Items[i].FindControl("controlId") to hook into it as you iterate.


But I ned to "Add" a control (label) to the datalist item template. how do I do this? I can do a DataList1.Items[i].FindControl("controlId"), but how do I add items to the list? Thanks for the reply by the way. I am on a short time table here. :)

Right, well, my point is that you're trying (I thought) to add a new label to that one panel that's got a bunch of labels on it, right? to do that, you need to first get an instance of the Panel (iterating over the control tree and returning the one you want). Then, you'd add it to that panel's control collection just like you normally would add a dynamic control, e.g. myPanel.Controls.Add(someLabelYouJustCreated);

Can I ask, though, what's the lifespan of these labels? Because, if they only last as long as the page is in view to the user, it might be easier to add them as clientside objects rather than serverside ones. Just soemthing to think about.


Thanks for the fast reply. You are right that I am trying to add labels dynamically to the panel inside the datalist. I get the intellisense for the datalist, but in the code behind it did not register (intellisense see) the panel. I cant do it on client side because the labels I am filling is coming from a database. So when I type hovPanel.xxx.xxx it says that hovpanel is not declared. thats where my problem is coming from.

I guess I need to get an instance of the panel, but I cant. I tried creating a new one in the code behind with the same name and it runs fine, but nothing gets added to the panel

i.e.

Dim hovpanel as panel = new panel (Although there is already a panel in the .aspx with the ID of "hovpanel"


Right, that's my whole point about the FindControl method. I don't do VB very well, so let me speak in abstract terms. you should say Dim hovPanel as Panel = findPanel("hovPanel") (or some such). findPanel() is a method you define which loops through the items of datalist1 to look for one with the id matching the above; I previously described this.

http://samples.gotdotnet.com/quickstart/aspplus/doc/webdatalist.aspx

That's a good example as well.


Ahh, I see where you are going. Thanks. I am going to give it a try.

Thanks Paul. I did this and it worked...

Dim lbl1As Label =New Label lbl1.Text ="PRINT ME"Dim yAs Integer For y = 0To DataList1.Items.Count - 1Dim hovpanelAs Panel = DataList1.Items(y).FindControl("hovpanel") hovpanel.Controls.Add(lbl1)Next
Now within the "FOR" loop and can run tests to see how many labels are there and how many to add and what not. Thanks a Million !!! :)


Glad I could help.

Wednesday, March 21, 2012

A ContentTemplate must be specified for UpdatePanel

Why has the Update Panel been changed in the new release so that a ContentTemplate must be specified. In my project i'd like to dynamically add controls to the panel in a user control.

Is this something that that is permanent?

Do not confuse the ASP.NET Panel control with the ASP.NET "Atlas"UpdatePanel.The ASP.NET "Atlas"UpdatePanel is a new control able to do partial rendering

In typical ASP.NET 2.0 applications, when a postback occurs, the page is re-rendered. This causes the page to flash in the browser. On the server, during postback, the page lifecycle executes. This ultimately raises the control event that caused the postback and runs the event handler (for example, a Button control's Click handler).

The ASP.NET "Atlas"UpdatePanel control eliminates the full page refresh. TheUpdatePanel control is used to mark a region in the page that will be updated when a postback occurs, but without the traditional postback behavior in the client. On the server, the page still handles the postback and runs normally, such as raising event handlers. But during the final rendering of the page, only the regions defined byUpdatePanel controls are created. This is referred to aspartial rendering.

Hope this helps

Irinel


I have a webpart server control class that i have extended. i'd like to add a update panel around the contents of the webpart so i can derive from this new class which has all the functionaly of webpart but its contents is with in an update panel.

I'd this like to add webparts derived from this extended class and add them dynamically to page via database.

I was having problems with the fact that u can not directly add controls to an update panel by adding controls i've solved this problem by deriving a class from ITemplate and then adding the template to the content template of the update panel.

I now have the problem the following problem

"The UpdatePanel 'Update' was not present when the page's InitComplete event was raised. This is usually caused when an UpdatePanel is placed inside a template. "

which i'm not saw how to resolve.

I've had success with a update panels dynamically around dynamically added webpartzones with in the onpreint event.

Any help would be appreciated.

Thanks

Paul