Sep 28, 2016, 3:28 PM
[CLOSED] Problem with load dynamic user control in tabpanel
Hi,
see my example, when I create the usercontrol, if I use a public method of usercontrol I take an error of undefined object in the script, because the script generated by public method is run before the object is created.
Please help me.
Thank you
Jimmy
page
see my example, when I create the usercontrol, if I use a public method of usercontrol I take an error of undefined object in the script, because the script generated by public method is run before the object is created.
Please help me.
Thank you
Jimmy
page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UCDynamic.aspx.cs" Inherits="Test.UCDynamic" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server" />
<ext:TabPanel ID="tbp" runat="server" Width="700" Height="500">
<Items>
<ext:Panel ID="pnl1" runat="server" Width="700" Height="500" Title="Panel 1">
<Items>
<ext:Label ID="lbl1" runat="server" Text="label label label" />
</Items>
</ext:Panel>
<ext:Panel ID="pnl2" runat="server" Width="700" Height="500" Title="Panel 2">
</ext:Panel>
</Items>
<DirectEvents>
<TabChange OnEvent="tbp_TabChange">
<EventMask ShowMask="true" />
</TabChange>
</DirectEvents>
</ext:TabPanel>
</form>
</body>
</html>
.cs of pageusing Ext.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Test
{
public partial class UCDynamic : System.Web.UI.Page
{
UCCombo ucCombo;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void tbp_TabChange(object sender, DirectEventArgs e)
{
if (string.Compare((sender as Ext.Net.TabPanel).ActiveTab.ID, "pnl2", true) == 0)
{
List<SBRow> values = new List<SBRow>();
for (int i = 0; i < 5; i++)
values.Add(new SBRow() { idValue = i.ToString(), description = string.Format("Value {0}", i.ToString()) });
ucCombo = (UCCombo)this.LoadControl("UCCombo.ascx");
ucCombo.ID = "userCtrlUcCombo";
pnl2.ContentControls.Clear();
ucCombo.LoadSbBox(values);
pnl2.ContentControls.Add(ucCombo);
pnl2.UpdateContent();
pnl2.UpdateLayout();
}
}
}
}
.ascx<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UCCombo.ascx.cs" Inherits="Test.UCCombo" %>
<ext:Panel ID="pnlCtrl" runat="server" Width="700" Height="500">
<Items>
<ext:SelectBox ID="sbBox" ClientIDMode="Static" runat="server"
TypeAhead="true"
ForceSelection="true"
SelectOnFocus="false"
TriggerAction="All"
Width="300"
ValueField="idValue"
DisplayField="description">
<Store>
<ext:Store ID="stSbBox" runat="server">
<Model>
<ext:Model ID="modelSbBox" runat="server">
<Fields>
<ext:ModelField Name="idValue" />
<ext:ModelField Name="description" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:SelectBox>
</Items>
</ext:Panel>
.cs of ascxusing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Test
{
public partial class UCCombo : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void LoadSbBox(List<SBRow> values)
{
this.stSbBox.DataSource = values;
this.stSbBox.DataBind();
}
}
public class SBRow
{
public string idValue;
public string description;
}
}
Last edited by fabricio.murta; Jan 03, 2017 at 9:52 PM.
Reason: no user feedback for 7+ days