usercontrol page_load not fired when programitically created

Discussion in 'ASP .Net Web Controls' started by tracstarr, Nov 26, 2006.

  1. tracstarr

    tracstarr Guest

    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
     
    tracstarr, Nov 26, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yan-Hong Huang[MSFT]
    Replies:
    6
    Views:
    687
    Yan-Hong Huang[MSFT]
    Jul 17, 2003
  2. Alfons Puig

    Page_Load event not fired

    Alfons Puig, Jan 26, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    2,663
    Ritwik
    May 25, 2011
  3. =?Utf-8?B?cm9iZXJ0bw==?=

    Generate web controls programitically

    =?Utf-8?B?cm9iZXJ0bw==?=, Nov 22, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    403
    =?Utf-8?B?cm9iZXJ0bw==?=
    Nov 22, 2004
  4. =?Utf-8?B?Q2FwdGFpbiBTZW5zaWJsZQ==?=

    Usercontrol derived from Usercontrol - masterpage init is fired tw

    =?Utf-8?B?Q2FwdGFpbiBTZW5zaWJsZQ==?=, Feb 3, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    473
    =?Utf-8?B?Q2FwdGFpbiBTZW5zaWJsZQ==?=
    Feb 3, 2006
  5. rockdale
    Replies:
    1
    Views:
    692
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Nov 16, 2006
Loading...

Share This Page