?
=?ISO-8859-15?Q?Tobias_Schr=F6er?=
Hi,
I have a web site with an UpdatePanel, a Label within that panel and a
Button outside the panel. All controls are created programatically (see
code below).
When I click the button to update the label's text, I get a
NullReferenceException in the page's Render method. My own code runs
without any problems.
Any one with some ideas? I already did some Google reseach but came out
with nothing that would help be
<code>
public partial class test : System.Web.UI.Page {
UpdatePanel up;
Label l1;
Panel p;
UpdateProgress upp;
Button b;
UpdateProgressOverlayExtender upoe;
protected override void OnPreInit(EventArgs e) {
base.OnPreInit(e);
// create dynamic controls
up = new UpdatePanel();
p = new Panel();
up.ContentTemplateContainer.Controls.Add(p);
l1 = new Label();
p.Controls.Add(l1);
this.form1.Controls.Add(up);
b = new Button();
this.form1.Controls.Add(b);
}
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
// control properties
l1.ID = "l1";
// some backgroud
p.Style.Value =
"width:100%; height:100px; text-align:center; " +
"background:#3366a4; border:solid 1px black;";
up.ID = "up";
up.ChildrenAsTriggers = false;
up.UpdateMode = UpdatePanelUpdateMode.Conditional;
b.Text = "Update Panel";
b.ID = "b";
b.Click += new EventHandler(this.ButtonClick);
// add button as update trigger
AsyncPostBackTrigger apt = new AsyncPostBackTrigger();
apt.ControlID = b.ClientID;
up.Triggers.Add(apt);
this.ScriptManager1.RegisterAsyncPostBackControl(b);
}
protected void ButtonClick(object sender, EventArgs e) {
// wait a litte
Thread.Sleep(2000);
// set label text
l1.Text = "Panel refreshed at " + DateTime.Now.ToString();
}
protected override void Render(HtmlTextWriter writer) {
try {
// here the error occurs
base.Render(writer);
} catch (Exception ex) {
writer.Write(ex.ToString());
}
}
}
</code>
Thanks,
Tobi
I have a web site with an UpdatePanel, a Label within that panel and a
Button outside the panel. All controls are created programatically (see
code below).
When I click the button to update the label's text, I get a
NullReferenceException in the page's Render method. My own code runs
without any problems.
Any one with some ideas? I already did some Google reseach but came out
with nothing that would help be
<code>
public partial class test : System.Web.UI.Page {
UpdatePanel up;
Label l1;
Panel p;
UpdateProgress upp;
Button b;
UpdateProgressOverlayExtender upoe;
protected override void OnPreInit(EventArgs e) {
base.OnPreInit(e);
// create dynamic controls
up = new UpdatePanel();
p = new Panel();
up.ContentTemplateContainer.Controls.Add(p);
l1 = new Label();
p.Controls.Add(l1);
this.form1.Controls.Add(up);
b = new Button();
this.form1.Controls.Add(b);
}
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
// control properties
l1.ID = "l1";
// some backgroud
p.Style.Value =
"width:100%; height:100px; text-align:center; " +
"background:#3366a4; border:solid 1px black;";
up.ID = "up";
up.ChildrenAsTriggers = false;
up.UpdateMode = UpdatePanelUpdateMode.Conditional;
b.Text = "Update Panel";
b.ID = "b";
b.Click += new EventHandler(this.ButtonClick);
// add button as update trigger
AsyncPostBackTrigger apt = new AsyncPostBackTrigger();
apt.ControlID = b.ClientID;
up.Triggers.Add(apt);
this.ScriptManager1.RegisterAsyncPostBackControl(b);
}
protected void ButtonClick(object sender, EventArgs e) {
// wait a litte
Thread.Sleep(2000);
// set label text
l1.Text = "Panel refreshed at " + DateTime.Now.ToString();
}
protected override void Render(HtmlTextWriter writer) {
try {
// here the error occurs
base.Render(writer);
} catch (Exception ex) {
writer.Write(ex.ToString());
}
}
}
</code>
Thanks,
Tobi