[Mono-bugs] [Bug 77278][Nor] New - Setting masterpage in OnPreInit
causes null reference exceptions when referencing controls on
the page
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Mon Jan 16 18:35:34 EST 2006
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by joe_audette at yahoo.com.
http://bugzilla.ximian.com/show_bug.cgi?id=77278
--- shadow/77278 2006-01-16 18:35:34.000000000 -0500
+++ shadow/77278.tmp.15296 2006-01-16 18:35:34.000000000 -0500
@@ -0,0 +1,165 @@
+Bug#: 77278
+Product: Mono: Class Libraries
+Version: 1.1
+OS: All
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: Sys.Web
+AssignedTo: gonzalo at ximian.com
+ReportedBy: joe_audette at yahoo.com
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Setting masterpage in OnPreInit causes null reference exceptions when referencing controls on the page
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+If you set the MasterPage for a page in the OnPreInit, the page loses its
+references to controls on the page.
+
+
+Steps to reproduce the problem:
+1. Create a page that uses a master page and set the master page in the
+OnPreInit
+2. Add any control, a label for example to the page and try to set its
+.Text property in Page_Load event
+
+
+Actual Results:
+You will get a null reference exception at the line of code where you set
+the.Text property of the control
+
+
+Expected Results:
+You will still be able to reference the controls on the page
+
+
+How often does this happen?
+Every time
+
+
+Additional Information:
+Example code that produces the problem on mono using the 2.0 runtime but
+works on windows
+
+Default.aspx:
+<%@ Page Language="C#" MasterPageFile="simple.master" %>
+
+<script runat="server">
+
+
+override protected void OnPreInit(EventArgs e)
+{
+
+ //this is a bug
+ //it works as expected on windows but
+ //causes a null reference in the page load event on mono
+
+ base.OnPreInit(e);
+ this.MasterPageFile = "simple2.master";
+
+}
+
+override protected void OnInit(EventArgs e)
+{
+
+ base.OnInit(e);
+
+
+
+}
+
+
+private void Page_PreInit (object sender, EventArgs e)
+{
+ this.MasterPageFile = "simple2.master";
+
+
+}
+
+
+private void Page_Load (object sender, EventArgs e)
+{
+ lblHelloWeb.Text = "Hello Web!";
+
+ //TestKey
+
+}
+
+private void btnTestConfig_Click (object sender, EventArgs e)
+{
+ //this displays the value on windows but not on mono r55575
+ this.lblTestConfig.Text =
+System.Configuration.ConfigurationSettings.AppSettings.Get("TestKey");
+
+
+
+}
+
+
+</script>
+
+<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
+Runat="server">
+
+Contents go here
+<hr />
+<asp:Label id="lblHelloWeb" runat="server" />
+<hr />
+<asp:Button id="btnTestConfig" runat="server" OnClick="btnTestConfig_Click"
+Text="Test Config" />
+<asp:Label id="lblTestConfig" runat="server" />
+
+</asp:Content>
+
+simple.Master:
+<%@ Master Language="C#"%>
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
+"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" >
+<head runat="server">
+ <title>Simple Master Page</title>
+</head>
+<body>
+ <form id="form1" runat="server">
+ <div>
+ What's inside the following box is a placeholder:
+ <div style='border:solid 2px red; padding:10px'>
+ <asp:contentplaceholder id="ContentPlaceHolder1"
+runat="server"></asp:contentplaceholder>
+ </div>
+ That's all!
+ </form>
+</body>
+</html>
+
+simple2.Master:
+<%@ Master Language="C#"%>
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
+"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" >
+<head runat="server">
+ <title>Simple Master Page</title>
+</head>
+<body>
+ <form id="form1" runat="server">
+ <h3>Simple2</h3>
+ <div>
+ What's inside the following box is a placeholder:
+ <div style='border:solid 2px red; padding:10px'>
+ <asp:contentplaceholder id="ContentPlaceHolder1"
+runat="server"></asp:contentplaceholder>
+ </div>
+ That's all!
+ </form>
+</body>
+</html>
More information about the mono-bugs
mailing list