Z
Zuel
Hi Folks.
So I have a small problem. My DoPostBack function is not writen to
the HTML page nor are the asp:buttons calling the DoPostBack.
My Goal is to create a totaly dynamic web page where the server
generates the HTML based on a passed in parameter. In our case,
CustomerID. Every Customer ges a branded website with there logos and
webpage etc.. To Avoid having 1 ASP.Net application running for each
client I am attempting a more dynamic rout.
To do this I need to be able to get the Branding stuff and inject it
into the webpage.
This is accomplished with various controls.
the .aspx is suposed to generate the clients branded web page. This
usually contains some logos and borders. So it's basically a table
with background images.
Then in this table I have a .ascx user control. It's job is to
dynamically insert the client selected controls. The client is able to
choose the layout and what controls to place on the page. So this
..ascx html is retrieved from the database keeping in mind it's simply a
table where each cell references prefabed controls.
The prefabed controls are created and generate like any other control
and nothing further should be necessary to insert them into the branded
webpage.
So the important stuff from the default.aspx looks like this:
<%@ Register TagPrefix="branding" TagName="MainPage"
Src="MainPage.ascx" %>
<%@ Page language="c#" Codebehind="default.aspx.cs"
AutoEventWireup="false" Inherits="SandBox._default" %>
<form id="branding" method="post" runat="server">
<branding:MainPage id="ETranWebPage"
runat="server"></etran:MainPage>
</form>
The Mainpage control is the .ascx from above and it's html content is
retrieved from a database call based on Client and looks something like
this.
<Table>
<TR><TD>formatted HTML</TD></TR>
<TR><TD>
<control1 runat="server">
<Properties>
<Property
name="buttonText">login</Property>
</Properties>
</control1>
</TD></TR>
<TR><TD>Some extra stuff</TD></TR>
</table>
The MainPage control overrides Render. In Render it parses the XHTML
above and dynamically inserts the correct control.
This information is also retrieved from an XML file and stored in a
hashtable. Key=id. Notice the id value matches the above xhtml's
element.
<Control source="testControl1.ascx" id="control1"
className="SandBox.testControl1"/>
Since I cannot simplifiy this too much.. Here is the code behind the
render.
private void Render(XmlNode node, HtmlTextWriter output) {
IEnumerator iEnum;
IEnumerator nl =
((XmlNode)node).ChildNodes.GetEnumerator();
if(nl.MoveNext()==false) {
output.Write(node.Value);
}else{
do {
XmlNode n = (XmlNode)nl.Current;
if(n.GetType() == typeof(XmlElement)) {
XmlElement e = (XmlElement)n;
if(mPageControls.ContainsKey(e.Name)) {
this.RenderETranControl(e,output);
}else {
if(n.ChildNodes.GetEnumerator().MoveNext()==false) {
output.Write(node.Value);
}else{
output.Write(n.OuterXml.Substring(0,n.OuterXml.IndexOf(">")+1));
this.Render(n,output);
output.Write("</");
output.Write(n.Name);
output.Write(">");
}
}
}else {
this.Render(n,output);
}
}while(nl.MoveNext());
}
}
public void RenderETranControl(XmlElement e, HtmlTextWriter
output) {
IEnumerator iEnum;
ETranWebControl control =
(ETranWebControl)mPageControls[e.Name];
Control c = (Control)LoadControl(control.source);
c.ID = control.id;
XmlAttributeCollection attributes = e.Attributes;
iEnum = attributes.GetEnumerator();
while(iEnum.MoveNext()) {
XmlAttribute attribute = (XmlAttribute)iEnum.Current;
}
iEnum =
e.GetElementsByTagName("Properties").GetEnumerator();
if(iEnum.MoveNext()) {
XmlElement properties = (XmlElement)iEnum.Current;
iEnum =
properties.GetElementsByTagName("Property").GetEnumerator();
while(iEnum.MoveNext()) {
XmlElement property = (XmlElement)iEnum.Current;
string propertyName =
property.GetAttribute("name");
string value = property.InnerText;
Type controlType = c.GetType();
try{
PropertyInfo pInfo =
controlType.GetProperty(propertyName);
pInfo.SetValue(c,value,null);
}catch(Exception ex) {
// Add Logging
}
}
}
// Controls.Add(c);
c.RenderControl(output);
}
Here is the control's html
<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="testControl1.ascx.cs" Inherits="SandBox.testControl1"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<asp:Button id="Button1" Text="Button" runat="server"></asp:Button>
and here we have the html output.
<script language="javascript" type="text/javascript">
</HEAD>
<body>
<form name="ETran" method="post" action="default.aspx"
id="ETran">
<input type="hidden" name="__VIEWSTATE"
value="dDwxMDQxNzA2MzQ5Ozs+K/wXsV22klaSnVgoGGt1YT6Hl94=" />
<Table><TR><TD>formatted HTML</TD></TR><TR><TD><input
type="submit" name="control1:Button1" value="login"
id="control1_Button1" />
</TD></TR><TR><TD>Some extra stuff</TD></TR></Table>
</form>
</body>
</HTML>
There is no doPostBack anything in the html output.
If you could help out I would greatly appreciate it!
Erik
So I have a small problem. My DoPostBack function is not writen to
the HTML page nor are the asp:buttons calling the DoPostBack.
My Goal is to create a totaly dynamic web page where the server
generates the HTML based on a passed in parameter. In our case,
CustomerID. Every Customer ges a branded website with there logos and
webpage etc.. To Avoid having 1 ASP.Net application running for each
client I am attempting a more dynamic rout.
To do this I need to be able to get the Branding stuff and inject it
into the webpage.
This is accomplished with various controls.
the .aspx is suposed to generate the clients branded web page. This
usually contains some logos and borders. So it's basically a table
with background images.
Then in this table I have a .ascx user control. It's job is to
dynamically insert the client selected controls. The client is able to
choose the layout and what controls to place on the page. So this
..ascx html is retrieved from the database keeping in mind it's simply a
table where each cell references prefabed controls.
The prefabed controls are created and generate like any other control
and nothing further should be necessary to insert them into the branded
webpage.
So the important stuff from the default.aspx looks like this:
<%@ Register TagPrefix="branding" TagName="MainPage"
Src="MainPage.ascx" %>
<%@ Page language="c#" Codebehind="default.aspx.cs"
AutoEventWireup="false" Inherits="SandBox._default" %>
<form id="branding" method="post" runat="server">
<branding:MainPage id="ETranWebPage"
runat="server"></etran:MainPage>
</form>
The Mainpage control is the .ascx from above and it's html content is
retrieved from a database call based on Client and looks something like
this.
<Table>
<TR><TD>formatted HTML</TD></TR>
<TR><TD>
<control1 runat="server">
<Properties>
<Property
name="buttonText">login</Property>
</Properties>
</control1>
</TD></TR>
<TR><TD>Some extra stuff</TD></TR>
</table>
The MainPage control overrides Render. In Render it parses the XHTML
above and dynamically inserts the correct control.
This information is also retrieved from an XML file and stored in a
hashtable. Key=id. Notice the id value matches the above xhtml's
element.
<Control source="testControl1.ascx" id="control1"
className="SandBox.testControl1"/>
Since I cannot simplifiy this too much.. Here is the code behind the
render.
private void Render(XmlNode node, HtmlTextWriter output) {
IEnumerator iEnum;
IEnumerator nl =
((XmlNode)node).ChildNodes.GetEnumerator();
if(nl.MoveNext()==false) {
output.Write(node.Value);
}else{
do {
XmlNode n = (XmlNode)nl.Current;
if(n.GetType() == typeof(XmlElement)) {
XmlElement e = (XmlElement)n;
if(mPageControls.ContainsKey(e.Name)) {
this.RenderETranControl(e,output);
}else {
if(n.ChildNodes.GetEnumerator().MoveNext()==false) {
output.Write(node.Value);
}else{
output.Write(n.OuterXml.Substring(0,n.OuterXml.IndexOf(">")+1));
this.Render(n,output);
output.Write("</");
output.Write(n.Name);
output.Write(">");
}
}
}else {
this.Render(n,output);
}
}while(nl.MoveNext());
}
}
public void RenderETranControl(XmlElement e, HtmlTextWriter
output) {
IEnumerator iEnum;
ETranWebControl control =
(ETranWebControl)mPageControls[e.Name];
Control c = (Control)LoadControl(control.source);
c.ID = control.id;
XmlAttributeCollection attributes = e.Attributes;
iEnum = attributes.GetEnumerator();
while(iEnum.MoveNext()) {
XmlAttribute attribute = (XmlAttribute)iEnum.Current;
}
iEnum =
e.GetElementsByTagName("Properties").GetEnumerator();
if(iEnum.MoveNext()) {
XmlElement properties = (XmlElement)iEnum.Current;
iEnum =
properties.GetElementsByTagName("Property").GetEnumerator();
while(iEnum.MoveNext()) {
XmlElement property = (XmlElement)iEnum.Current;
string propertyName =
property.GetAttribute("name");
string value = property.InnerText;
Type controlType = c.GetType();
try{
PropertyInfo pInfo =
controlType.GetProperty(propertyName);
pInfo.SetValue(c,value,null);
}catch(Exception ex) {
// Add Logging
}
}
}
// Controls.Add(c);
c.RenderControl(output);
}
Here is the control's html
<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="testControl1.ascx.cs" Inherits="SandBox.testControl1"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<asp:Button id="Button1" Text="Button" runat="server"></asp:Button>
and here we have the html output.
<script language="javascript" type="text/javascript">
</HEAD>
<body>
<form name="ETran" method="post" action="default.aspx"
id="ETran">
<input type="hidden" name="__VIEWSTATE"
value="dDwxMDQxNzA2MzQ5Ozs+K/wXsV22klaSnVgoGGt1YT6Hl94=" />
<Table><TR><TD>formatted HTML</TD></TR><TR><TD><input
type="submit" name="control1:Button1" value="login"
id="control1_Button1" />
</TD></TR><TR><TD>Some extra stuff</TD></TR></Table>
</form>
</body>
</HTML>
There is no doPostBack anything in the html output.
If you could help out I would greatly appreciate it!
Erik