PDA

View Full Version : Dynamically add components in ASP.NET contentpages



jonahcarneskog
30 Oct 2007, 1:44 AM
Fellas, I'm kind of new here, and need some assistance. I haven't found anything on this in the forum, but sorry if I've missed some info.

Here's the deal:

I have the layout of the page created in the asp.net Master page. It is pretty simple, just north, west and center. I want the center page to be updatable with asp.net content pages.

Now, is there a way where I can add ext calls from the contentpages, so I can easily choose what components I use for each contentpage?

Pseudo code for a contentpage would be something like this:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div id="toolbar"></div>
<div id="content">
Lorem Ipsum....
</div>

<script type="text/javascript">
var tb = new Ext.Toolbar();
tb.render('toolbar');

tb.add({
text:'',
menu: menu // My menu would be created, but I'll skip that code for now
});
</script>
</asp:Content>

If this would be possible, it would be awesome!
Has anyone tried this? :-?

evant
30 Oct 2007, 2:49 AM
Yep, you can do that, as long as the master page doesn't mangle the ID's of things like it tends to do on server controls (if you're using them).

But before you do the building in your master page, you'd want to check whether they actually exist, so for example:

All JS is rendered in the MasterPage
West contains <div id="toolbar">, it is in it's own ContentPage
East contains <div id="menu">, it is in it's own ContentPage
West/East may be on or off



if (Ext.get('toolbar'))
{
//elem exists, build tb.
}

jonahcarneskog
30 Oct 2007, 11:35 PM
Hmm, I've tried different approaches for a day now but haven't been able to get it to work.
I get "C has no properties"

I am using 2.0, can that be one of the issues??

All I want is to add a menu-toolbar to an existing panel, and be able to initialize a new toolbar for every different contentpage I load in asp.net

If anyone could point me in the right direction I would really appreciate it. :)

Cheers!