PDA

View Full Version : [CLOSED] The control with ID 'MainContent_ctl69' not found



Geenin
Mar 17, 2014, 4:26 PM
I got the error message when I added MasterPageFile in the aspx file.

here is my code:

aspx


<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent" >
.................
<ext:Portlet ID="PortletGroupView" runat="server" Layout="TableLayout" Closable="false" Draggable="false" Frame="false" Collapsible="false" Border="false">
<LayoutConfig>
<ext:TableLayoutConfig Columns="3" />
</LayoutConfig>
<Items>
</Items>
</ext:Portlet>
........................
</asp:Content>


C# Code


public class GROUP_HOST
{
public String GROUP_NAME { get; set; }
public String DURATION { get; set; }
public String COUNT_OK { get; set; }
public String COUNT_WARNING { get; set; }
public String COUNT_NG { get; set; }
}

public partial class Default : System.Web.UI.Page
{
protected void Load_Group_View()
{
List<GROUP_HOST> ghlst = new List<GROUP_HOST>();
for (int i = 1; i < 10; i++)
{
GROUP_HOST gh = new GROUP_HOST();
gh.GROUP_NAME = "Group_" + i;
gh.DURATION = i * 2 + "D" + 1 * i + "H" + 2 * i + "m";
gh.COUNT_NG = 2 * i + "";
gh.COUNT_OK = 3 * i + "";
gh.COUNT_WARNING = 1 * i + "";
ghlst.Add(gh);
}
foreach (GROUP_HOST gh in ghlst)
{
Ext.Net.Button btnOK = new Ext.Net.Button
{
Scale = ButtonScale.Large,
Width = 50,
Cls = "btn-green",
Text = "<span style='color:while;'>"+gh.COUNT_OK+"</span>",
AutoDataBind = true
};
Ext.Net.Button btnWarning = new Ext.Net.Button
{
Scale = ButtonScale.Large,
Width = 50,
Cls = "btn-yellow",
Text = "<span style='color:while;'>" + gh.COUNT_WARNING + "</span>",
AutoDataBind = true
};
Ext.Net.Button btnNG = new Ext.Net.Button
{
Scale = ButtonScale.Large,
Width = 50,
Cls = "btn-red",
Text = "<span style='color:while;'>" + gh.COUNT_NG + "</span>",
AutoDataBind = true
};

btnOK.DirectEvents.Click.Event += GroupViewClick;
btnWarning.DirectEvents.Click.Event += GroupViewClick;
btnNG.DirectEvents.Click.Event += GroupViewClick;

Ext.Net.Panel pn = new Ext.Net.Panel
{
Title = gh.GROUP_NAME,
FrameHeader = true,
BodyPadding = 10,
Frame = true,
Width = 200,
Items = {
new Ext.Net.Label{
Text = gh.DURATION,
Height = 100,
Width=100
},
new Container{
Items = {
btnOK,btnWarning,btnNG
}
}
}

};
this.PortletGroupView.Items.Add(pn);
}
}

protected void GroupViewClick(object sender, EventArgs e)
{
String aaa = ((Ext.Net.Button)sender).Text;
}
}


When I trigger the button click event, will get error "The control with ID 'MainContent_ctl69' not found".
but it was work when I didn't use MasterPageFile, please help, thanks a lot.

Daniil
Mar 18, 2014, 6:33 AM
Hi @Geenin,

Could you, please, clarify where the Load_Group_View method is being called?

Geenin
Mar 18, 2014, 7:34 AM
Hi @Geenin,

Could you, please, clarify where the Load_Group_View method is being called?



protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.Load_Group_View();
}
}


It's called by Page_Load

Geenin

Daniil
Mar 18, 2014, 11:30 AM
Thanks.


but it was work when I didn't use MasterPageFile, please help, thanks a lot.

Even without a master page, if you created the Buttons under this condition

if (!IsPostBack)
then I would say it should not work.

A control's DirectEvent requires an instance of that control on client side. This condition

if (!IsPostBack)
means that you don't recreate the Buttons when a DirectEvent occurs.

Also I would suggest to set up IDs for the Buttons explicitly.

Geenin
Mar 18, 2014, 1:28 PM
Thanks.



Even without a master page, if you created the Buttons under this condition

if (!IsPostBack)
then I would say it should not work.

A control's DirectEvent requires an instance of that control on client side. This condition

if (!IsPostBack)
means that you don't recreate the Buttons when a DirectEvent occurs.

Also I would suggest to set up IDs for the Buttons explicitly.


Thanks Daniil ! It works... very appreciate....... :-)


Geenin