PDA

View Full Version : [CLOSED] ext.UserControlLoader in CodeBehind



supera
Feb 03, 2012, 3:13 PM
Hi

I try add my own usercontrol in a tabPanel. Im fail!

I use a UserControlLoader... in my usercontrol, Im use only ext.net components.

The code to Load my own usercontrol in TabPanel follows:

Occurs two problems:
1 - Add only one tab in tabPanel... I try add many tabs.
2 - The content of usercontrolLoader, (my own Usercontrol) is not show.
3 -

I believe that the problem is the usercontrolloader.addto. Is this a correct mode of add controls in UserControlLoader?
Is there any example for me to follow?



Dim tabPanelConfig As Ext.Net.Panel.Config = New Ext.Net.Panel.Config
Dim tabContext As ExplorerWebContext = New ExplorerWebContext
Dim tabPanel As Ext.Net.Panel
Dim ucLoader As Ext.Net.UserControlLoader = New Ext.Net.UserControlLoader

tabContext.Start(Context)

With tabPanelConfig
.Title = tabContext.ContextoDescription
.Closable = True
.Border = True
.Padding = 6
End With

tabPanel = New Ext.Net.Panel(tabPanelConfig)
ucLoader.AddTo(tabContext)
tabPanel.Items.Add(ucLoader)
tabWebExplorer.Items.Add(tabPanel)
tabWebExplorer.Render()

Daniil
Feb 03, 2012, 5:01 PM
Hi,

Please clarify the requirement.

Do you need to add tabs during Page_Load or DirectEvent?

What is the content of tabs - a user control?

supera
Feb 03, 2012, 5:32 PM
Hi Daniil...

I am sorry if I was not clear in my request!


Do you need to add tabs during Page_Load or DirectEvent?
I need add tabs in DirectEvent


What is the content of tabs - a user control?
Yes, I add in tab my own usercontrol.

Daniil
Feb 03, 2012, 6:44 PM
Please look at the example.

Example Page

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void AddTab(object sender, DirectEventArgs e)
{
UserControlLoader ucl = new UserControlLoader();
ucl.Path = "TestUC.ascx";

Ext.Net.Panel p = new Ext.Net.Panel("Tab");

p.Items.Add(ucl);

this.TabPanel1.Items.Add(p);

p.Render();
}
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:TabPanel ID="TabPanel1" runat="server" />
<ext:Button runat="server" Text="Add tab" OnDirectClick="AddTab" />
</form>
</body>
</html>


Example User Control

<%@ Control Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<ext:Panel runat="server" Html="Hello from User Control. I am 1" />

<ext:Panel runat="server" Html="Hello from User Control. I am 2" />

supera
Feb 06, 2012, 9:30 AM
Hi Daniil,

Thanks for your example...

Its is very similar to what Im doing... But I get different errors in my project...

I have a error in YOUR example... Lets start with this.
1 - In YOUR example, set the Closable property of tab for True, please.
2 - Run test page.
3 - Add 4 tabs.
4 - Close first or last tab... you will get the following error.

Runtime Error in Microsoft JScript: Type mismatch.
3805

Daniil
Feb 06, 2012, 10:31 AM
I was unable to reproduce the error following the steps you provided.

Any more changes?

What browser do you test with?

supera
Feb 06, 2012, 11:22 AM
Hi Daniil...

You're right about seem to be a browser issue.

After your comment, I ran the test in FireFox 9.0.1, Opera 11.61, Google Chrome 16.0.912.77, and the error did not occur in any of these browsers.

In Internet Explorer version 9.0.8112.16421, update version 9.0.4 (kb2618444), the error occurs.[

3806

Daniil
Feb 06, 2012, 12:18 PM
I've tested with the same IE9, but still can't reproduce the problem.

I'm testing under Windows 7 Home Premium.

What OS do you test with?

supera
Feb 06, 2012, 12:32 PM
Windows 7 Professional with Service Pack 1 64 Bits.
Processor Intel Core i3-2100 CPU 3.10 GHZ
Ram 4 GB

Would you try to access my computer via logmein, teamviewer, vnc or other?
If you want to try, please add me on windows live messenger gefferson@superainfo.com.br.

Daniil
Feb 06, 2012, 2:24 PM
Windows 7 Professional with Service Pack 1 64 Bits.
Processor Intel Core i3-2100 CPU 3.10 GHZ
Ram 4 GB


I have the SP1 and 64 bits as well. The single difference is "Proffessional" and "Home Premium". Well, I don't think it might be a reason of the problem, but not 100% sure.

Also I don't think the PC processor and RAM might cause the problem.

Could you double ensure were there no more changes in my example on your side apart from Closable="true"? Did you port it on VB?


Would you try to access my computer via logmein, teamviewer, vnc or other?
If you want to try, please add me on windows live messenger gefferson@superainfo.com.br.

I think it's not required on this stage, but I will keep it in mind.

supera
Feb 06, 2012, 2:41 PM
Hi Daniil

1 - The only change is Closable property.
2 - I keep the example code in C# for my tests.

Follow the codes

Test2.aspx


<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void AddTab(object sender, DirectEventArgs e) {
UserControlLoader ucl = new UserControlLoader();
ucl.Path = "TestUC.ascx";
Ext.Net.Panel p = new Ext.Net.Panel("Tab");
p.Closable = true;
p.Items.Add(ucl);
this.TabPanel1.Items.Add(p);
p.Render();
}
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server">
<title>Ext.NET v2 Example</title></head><body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:TabPanel ID="TabPanel1" runat="server" />
<ext:Button ID="Button1" runat="server" Text="Add tab" OnDirectClick="AddTab" />
</form></body></html>


TestUC.ascx



<%@ Control Language="C#" %> <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<ext:Panel ID="Panel1" runat="server" Html="Hello from User Control. I am 1" />
<ext:Panel ID="Panel2" runat="server" Html="Hello from User Control. I am 2" />

Daniil
Feb 06, 2012, 6:33 PM
Well, your code is not the same, there are IDs for the Panels in the user control.

It causes an ids conflict since the client ids of the Panels are the same in each tab.

Please set up a unique ID for a user control of each tab, like this:

UserControlLoader ucl = new UserControlLoader();
ucl.Path = "TestUC.ascx";
ucl.UserControlID = "TestUC" + index;
where index = 0 .. n.

supera
Feb 06, 2012, 6:53 PM
Daniil, thanks a lot for your help!

I feel sorry for this problem. It seems to have been caused by my low knowledge or inattention. Sorry

I have one more question relating to these issues of ID:
In usercontrol I'm creating, I have some controls ext.net. I need to create a unique ID for each one, or setting a unique ID to each Usercontrol, things will be resolved?

Thanks for your help, again.

Daniil
Feb 06, 2012, 7:39 PM
In your case you can set up a unique ID just for a user control. Be default, the client ids of the Ext.NET controls within that user control will be the concatenation of the user control's ID and the Ext.NET control's ID, for example, "TestUC1_Panel1".

supera
Feb 07, 2012, 10:19 AM
Hi Daniil...

As you said, setting a unique UserControlID, this problem does not occurs.

Thanks a lot.

I would like to generate the index you mentioned using TabPanel1.Items.Count... but, TabPanel1.Items.Count always returns zero.

I add the panels in tabPanel follow your example code, as bellow...



this.TabPanel1.Items.Add(p);


I will also need a way of determining whether the Panel has been added in TabPanel... if tabPanel1.Items contain the added UserControlLoader, I can achieve my goals. But, the Items collection seems to be empty.

Daniil
Feb 07, 2012, 10:28 AM
Neither ASP.NET or Ext.NET don't recreate any controls automatically.

If you create a control during one DirectEvent, it won't appear during another DirectEvent if you don't recreate it.

Therefore the Items collection is empty.

supera
Feb 07, 2012, 5:14 PM
Ok...

I think this closes the issue ... thanks a lot for your help!