Showing posts with label creating. Show all posts
Showing posts with label creating. Show all posts

Monday, March 26, 2012

How do I dynamically create TabPanels in codebehind?

I have tried creating TabPanels dynamically in Page_Init but they aren't showing up even though I do see them when doing View Source on the resulting page. When I add them statically with the designer, they do show up. I am using 10618 version of the toolkit.

Here is a code snippet:

protected void Page_Init(object sender, EventArgs e){ AjaxControlToolkit.TabPanel tp =new AjaxControlToolkit.TabPanel(); tp.ID ="DynamicTab1"; tp.HeaderText ="DynamicTab1" Label tabContents =new Label(); tabContents.Text = tp.HeaderText; tp.Controls.Add(tabContents); ExistingTabContainer.Tabs.Add(tp);}

Hi,

I'd do this dynamic tab panel creation this way (it also works in the Page_Load event handler):

protected override void OnInit(EventArgs e){base.OnInit(e);// Create the tab panel's content container Control tabContent =new Control(); TabPanel tab =new TabPanel(); tab.ID ="tabPanel1"; tab.HeaderText ="Dynamic Panel"; Label label =new Label(); label.Text ="This is a dynamic tab panel"; tabContent.Controls.Add(label); tab.Controls.Add(tabContent);this.tabContainer1.Tabs.Add(tab);}

This pice of code works for me perfect. The tabContainer1 control is of type AjaxControlToolkit.TabContainer and is declared on the page this way:

<ajaxcc:TabContainer ID="tabContainer1" runat="server"></ajaxcc:TabContainer>

Kind regards,

sbogus.



sbogus, I got it to work using your sample code. I really appreciate your help.

Cheers!

Ron

How Do I Dynamically Add Profile Properties

I am creating a series of panels of data (dynamically) that I want to have the user drag around with theDragOverlayExtender. The problem is that I need to save their position on the page so that the next time they load the page, their panels are right where they left them. I have added theProfileScriptService and for eachDragOverlayExtender that I am creating, I am setting theProfileProperty to a unique value. The problem is that there can be any number of panels, so I cannot present values in the config file.

How can I dynamically add profile properties?

Also, (as a side question) how can I read and set the relative positions of the panels that have been moved via theDragOverlayExtender?

Thanks!

- David E. Craig

I'm not sure about the addition of dynamic profile properties, but since the ProfileScriptService is a core Atlas control, you might considerposting the question in one of the dedicated Atlas forums. Regarding the panel position, it's looking to me like the Location/location property of the DragPanelExtender/Behavior should do what you need?

Sorry, but has the dragoverlayextender an Location property?

Thanks,

Rodrigo Sendin


It did before ASP.NET AJAX Beta 1 when I made the recommendation. :) It's been removed, but may be back soon as time/underlying framework permits.

How do I create a WebService with mandatory elements in the request?

I need a bit of assitance creating a WebService. Say that I have something like this -

'The objectsPublic Class productPublic nameAs StringPublic priceAs DecimalEnd ClassPublic Class orderPublic customerAs StringPublic productsAs List(Of product)End Class'The DB layerPublic orderDBPublic Function commitOrder(orderAs order)As IntegerDim orderIdAs Integer'DB code ommittedReturn orderIdEnd FunctionEnd Class'The Web Service<System.Web.Services.WebService(Namespace:="http://localhost/")> _<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _<ToolboxItem(False)> _Public Class order_wsInherits System.Web.Services.WebService <WebMethod()> _Public Function commitOrder(ByVal orderAs order)As Integer Dim orderDBAs New orderDB()Return orderDB.commitOrder(order)End FunctionEnd Class
The WSDL I get contains something like -

<s:element name="commitOrder"><s:complexType><s:sequence><s:element minOccurs="0" maxOccurs="1" name="order" type="tns:order" /></s:sequence></s:complexType></s:element><s:complexType name="order"><s:sequence><s:element minOccurs="0" maxOccurs="1" name="customer" type="s:string" /><s:element minOccurs="0" maxOccurs="1" name="products" type="tns:ArrayOfproducts" /></s:sequence></s:complexType><s:complexType name="ArrayOfproducts"><s:sequence><s:element minOccurs="0" maxOccurs="unbounded" name="product" nillable="true" type="tns:product" /></s:sequence></s:complexType><s:complexType name="product"><s:sequence><s:element minOccurs="0" maxOccurs="1" name="name" type="s:string" /><s:element minOccurs="0" maxOccurs="1" name="price" type="s:decimal" /></s:sequence></s:complexType>

Notice that everything is minoccurs="0" and the product entry in the ArrayOfproducts is nillable. How do I make it so that specific bits are required (minoccurs="1" and/or product element not nillable)?

Thanks

Martin

You could set a web service header so they always send you those requiered fields.


I'm not sure that I understand what you mean. But, just to elaborate on what I am looking for, the WSDL should contain tags that specify minOccurs="1".


Might be better to use discrete parameters rather than sending an order object. Most people find that more straightforward to use.


How would you control mandatory / optional elements using discrete parameters?

In any case, I'm already severely restricted in my attempts to use best coding practices by the inadequacies of .Net's WebService implementation. If I can't even control mandatory elements in this scenario I'll give it a miss and look at using Java and Mule.

Saturday, March 24, 2012

How come the toolkit is only available as server controls?

Am I missing something or is this by design? It would be really nice to programmaticly instantiate/dispose etc.. for creating a modal dialog and the other useful behaviors in the toolkit. Just for a laugh, I decided to copy over the JS files for the dropdown menu and got it working (minus some strange errors where dispose() is being called on undefined objects) but it was rather a cumbersome process having to include all the JS files and dependencies. Anyone else doing this sort of thing? Any chance there is a version of the toolkit that is not server control based?

function createDropDownMenu() { var panel = document.createElement("div"); panel.className ="ContextMenuPanel"; panel.style.display ="none"; panel.style.width ="100px"; panel.style.height ="100px"; panel.style.visibility ="hidden"; var target = $get('placeholderDiv').appendChild(panel); var dd_menu =new AjaxControlToolkit.DropDownBehavior($get('TextLabel')); dd_menu.set_dropDownControl(panel); dd_menu.set_dropDownControlID(TextLabel); dd_menu.set_dropArrowImageUrl("images/drop-arrow.gif"); dd_menu.initialize(); dd_menu.show(); }
anyone?

This has been requested, but it's a bit of work to create a process that will extract all the files and put them in the right dependency order, etc. It's something I'd like to do, but isn't super high-priority.

The trick to do this is as follows:

1) Get the scripts loaded by instantiating an extender and pointing it at a dummy control.

<asp:Label ID="dummy" style="display:none;"/>

<ajaxToolkit:SomeExtender TargetControlID="dummy"/>

2) Instantiate the behavior using the $create() helper, notnew

var behavior = $create(AjaxControlToolkit.SomeBehaior, {prop:value,prop2:value2}, null, null, $get('someElement'));


Excellent. This works great. Thanks for the tip!

I guess the ordering in which the scripts load has something to do with it. I modified my code to use your method and it runs cleanly now with no errors.


Good - yeah if you're okay with that little hand wave, then you don't have to worry about that stuff...