Custom ExpressionBuilder + ParseControl. No Joy? [modified]
-
Using a custom ExpressionBuilder doesnt seem to work with ParseControl (dynamically adding controls, that are using the custom ExpressionBuilder) Works fine with the build-in Resources ExpressionBuilder though. Anyone have a solution/workaround for this? Or even an explanation for why it doesnt work. Example
protected void Page\_Load(object sender, EventArgs e) { string s = (@" <hr /> 1: <asp:Label ID=""Label1"" Text=""<%$ Resources:language, Greeting %>"" runat=""server"" /> <br /> 2: <asp:Label ID=""Label2"" Text=""<%$ IHLPResource:Greeting %>"" runat=""server"" /> <hr /> "); Control ctrl = ParseControl(s); Page.Form.Controls.Add(ctrl); }
1: Gets rendered just fine, while 2: fails (no error, the value just doesnt get rendered) ie. the output is:
1: Hi
2:(2: should say "\\\Output from custom ExpressionBuilder///" - See code below) If I simply add the above to the aspx page, it works fine (ie. my custom ExpressionBuilder is not the cause of failure) -------------------------------------------------------------------------------------------- CODE - For quick copy/paste to test yourself -------------------------------------------------------------------------------------------- DynTest.aspx
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="DynTest.aspx.cs"
Inherits="IHLP2007PoC.DynTest" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>WelcomeLabel Test</title>
</head>
<body>
<form id="form1" runat="server">
<hr />
1: <asp:Label ID="Label1" Text="<%$ Resources:language, Greeting %>" runat="server" />
<br />
2: <asp:Label ID="Label2" Text="<%$ IHLPResource:Greeting %>" runat="server" />
<hr />
</form>
</body>
</html>DynTest.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;using System.Xml;
namespace IHLP20
-
Using a custom ExpressionBuilder doesnt seem to work with ParseControl (dynamically adding controls, that are using the custom ExpressionBuilder) Works fine with the build-in Resources ExpressionBuilder though. Anyone have a solution/workaround for this? Or even an explanation for why it doesnt work. Example
protected void Page\_Load(object sender, EventArgs e) { string s = (@" <hr /> 1: <asp:Label ID=""Label1"" Text=""<%$ Resources:language, Greeting %>"" runat=""server"" /> <br /> 2: <asp:Label ID=""Label2"" Text=""<%$ IHLPResource:Greeting %>"" runat=""server"" /> <hr /> "); Control ctrl = ParseControl(s); Page.Form.Controls.Add(ctrl); }
1: Gets rendered just fine, while 2: fails (no error, the value just doesnt get rendered) ie. the output is:
1: Hi
2:(2: should say "\\\Output from custom ExpressionBuilder///" - See code below) If I simply add the above to the aspx page, it works fine (ie. my custom ExpressionBuilder is not the cause of failure) -------------------------------------------------------------------------------------------- CODE - For quick copy/paste to test yourself -------------------------------------------------------------------------------------------- DynTest.aspx
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="DynTest.aspx.cs"
Inherits="IHLP2007PoC.DynTest" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>WelcomeLabel Test</title>
</head>
<body>
<form id="form1" runat="server">
<hr />
1: <asp:Label ID="Label1" Text="<%$ Resources:language, Greeting %>" runat="server" />
<br />
2: <asp:Label ID="Label2" Text="<%$ IHLPResource:Greeting %>" runat="server" />
<hr />
</form>
</body>
</html>DynTest.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;using System.Xml;
namespace IHLP20