T
tracstarr
I've got a usercontrol that doesn't load properly because it's
page_load /onprerender events are not fired when I create the control
programatically. Here is the method i use to render the html for the
control. I pass in my usercontrol which is loaded as follows:
Control c1 = LoadControl("AccountDetails.ascx");
private static string RenderWithOutForm(Control ctrl)
{
Page p = new Page();
HtmlForm hf = new HtmlForm();
hf.Controls.Add(ctrl);
p.Controls.Add(hf);
//ctrl.DataBind();
System.Text.StringBuilder SB = new
System.Text.StringBuilder();
System.IO.StringWriter SW = new System.IO.StringWriter(SB);
System.Web.UI.HtmlTextWriter htmlTW = new
System.Web.UI.HtmlTextWriter(SW);
try
{
p.EnableEventValidation = false;
p.DesignerInitialize();
p.RenderControl(htmlTW);
p = null;
//now remove the form tags and viewstate div. (first 5
lines and last line)
char[] splitChar = { '\n' };
string[] strArr;
strArr = SB.ToString().Split(splitChar);
string nStr = "";
//iterate over the Array
//which contains each line of the file
for (int x = 0; x < strArr.Length; x++)
{
if ((x > 4)&&(x<(strArr.Length -1)))
{
nStr = nStr + strArr[x].ToString();
}
}
return nStr;
}
Any ideas?
thanks
page_load /onprerender events are not fired when I create the control
programatically. Here is the method i use to render the html for the
control. I pass in my usercontrol which is loaded as follows:
Control c1 = LoadControl("AccountDetails.ascx");
private static string RenderWithOutForm(Control ctrl)
{
Page p = new Page();
HtmlForm hf = new HtmlForm();
hf.Controls.Add(ctrl);
p.Controls.Add(hf);
//ctrl.DataBind();
System.Text.StringBuilder SB = new
System.Text.StringBuilder();
System.IO.StringWriter SW = new System.IO.StringWriter(SB);
System.Web.UI.HtmlTextWriter htmlTW = new
System.Web.UI.HtmlTextWriter(SW);
try
{
p.EnableEventValidation = false;
p.DesignerInitialize();
p.RenderControl(htmlTW);
p = null;
//now remove the form tags and viewstate div. (first 5
lines and last line)
char[] splitChar = { '\n' };
string[] strArr;
strArr = SB.ToString().Split(splitChar);
string nStr = "";
//iterate over the Array
//which contains each line of the file
for (int x = 0; x < strArr.Length; x++)
{
if ((x > 4)&&(x<(strArr.Length -1)))
{
nStr = nStr + strArr[x].ToString();
}
}
return nStr;
}
Any ideas?
thanks