PDA

View Full Version : [CLOSED] Add panel from codebehind



Jurke
Sep 17, 2008, 8:25 AM
Hi,

Im trying to add a panel object from codebehind. When i compile and run the page nothing shows. How can solve this?






protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < 2; i++)
{
Coolite.Ext.Web.Panel pnlTest = new Coolite.Ext.Web.Panel();
pnlTest.Title = i.ToString();
pnlTest.ID = i.ToString();
pnlTest.Html = "Content " + i;
divTest.Controls.Add(pnlTest);
}
}




<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test2.aspx.cs" Inherits="Test2" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">

<ext:ScriptManager ID="ScriptManager1" runat="server">
</ext:ScriptManager>

<div runat="server" id="divTest">



</form>
</body>
</html>


Best regards
Mikael

Timothy
Sep 17, 2008, 8:33 AM
Hello,

Here is a simplified example of what you are trying to achieve:



<%@ Page Language="C#" %>
<%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Coolite.Ext.Web.Panel pnlTest = new Coolite.Ext.Web.Panel();

pnlTest.Title = "Test";
pnlTest.Html = "Hello World";

pnlParent.Controls.Add(pnlTest);
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Word</title>
</head>
<body>
<p><a href="Example.aspx">Reload</a></p>
<form id="form1" runat="server">
<ext:ScriptManager ID="ScriptManager1" runat="server" />
<asp:PlaceHolder ID="pnlParent" runat="server" />
</form>
</body>
</html>


Don't set the ID of the new Ext:Panel to a number, it won't work :)

Cheers,
Timothy

Jurke
Sep 17, 2008, 8:45 AM
Hi,

Thanks, now it is working. The problem was my Panel.ID which didnīt accept numeric values only.

Best regards
Mikael