Wednesday, March 21, 2012

Partial Page Render not working with Master page

I have a child page using partial page rendering and the web controls are created programmatically. Ajax seems to have a problem with control ID naming when you create your web controls dynamically. When I run this it gives me an object instance error indicating the named control "Lable1" doesn't exist.

Has anyone else run into this problem?

Is there a work around?

Master Page

<"C#"AutoEventWireup="true"CodeFile="MasterPage.master.cs"Inherits="MasterPage" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""">



<title>Untitled Page</title>











CS child page

<"C#"MasterPageFile="~/MasterPage.master"Title="Untitled Page" %>



protectedvoid Page_Load(object sender,EventArgs e)


UpdatePanel up1 =newUpdatePanel();

up1.ID ="UpdatePanel1";

up1.UpdateMode =UpdatePanelUpdateMode.Conditional;

Button button1 =newButton();

button1.ID ="Button1";

button1.Text ="Submit";

button1.Click +=newEventHandler(Button_Click);

Label label1 =newLabel();

label1.ID ="Label1";label1.Text ="A full page postback occurred.";





protectedvoid Button_Click(object sender,EventArgs e)


((Label)Page.FindControl("Label1")).Text ="Panel refreshed at " +DateTime.Now.ToString();








Create your controls in the Page_Init vs the Page_Load method.


Damien -

I tried creating the controls in the Page_Init and it still will not work. The referrence to the control is still null. Is the page lifecycle timing wrong with the Button_Click event?

Try refering your control with:


I don't have access to the UpdatePanel at design time.


Thank you. Seems to work referencing the UpdatePanel "up1". Although you must instantiate "up1" as global. Simple but necessary.

No comments:

Post a Comment