Click here to Skip to main content
15,867,453 members
Home / Discussions / ASP.NET
   

ASP.NET

 
Questioncant obtain new value of html control attribute Pin
shovaly23-Oct-08 6:00
shovaly23-Oct-08 6:00 
AnswerRe: cant obtain new value of html control attribute Pin
Brij23-Oct-08 18:22
mentorBrij23-Oct-08 18:22 
QuestionSystem.Data.OleDb.OleDbException: 'Y:\Macros\WFAC' is not a valid path Pin
farmer23-Oct-08 5:59
farmer23-Oct-08 5:59 
AnswerRe: System.Data.OleDb.OleDbException: 'Y:\Macros\WFAC' is not a valid path Pin
AhsanS23-Oct-08 18:31
AhsanS23-Oct-08 18:31 
GeneralRe: System.Data.OleDb.OleDbException: 'Y:\Macros\WFAC' is not a valid path Pin
farmer24-Oct-08 3:02
farmer24-Oct-08 3:02 
QuestionHow to raise Session_End event at Global.asax if I use SQLServer for session state. Pin
mdpavel23-Oct-08 4:50
mdpavel23-Oct-08 4:50 
AnswerRe: How to raise Session_End event at Global.asax if I use SQLServer for session state. Pin
Guffa23-Oct-08 14:52
Guffa23-Oct-08 14:52 
QuestionCustom ExpressionBuilder + ParseControl. No Joy? [modified] Pin
mgkr23-Oct-08 4:17
mgkr23-Oct-08 4:17 
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 IHLP2007PoC {
  public partial class DynTest : System.Web.UI.Page {
    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);
    }
  }
}


IHLPResourceExpressionBuilder.cs
using System;
using System.Data;
using System.Configuration;
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.CodeDom;
using System.ComponentModel;
using System.Web.Compilation;


namespace IHLP2007PoC.Code {
  public class IHLPResourceExpressionBuilder : ExpressionBuilder {

    public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object
         parsedData, ExpressionBuilderContext context) {
      string evaluationMethod = "GetResourceString";
      CodeTypeReferenceExpression thisType = new CodeTypeReferenceExpression(base.GetType());
      CodePrimitiveExpression expression = 
         new CodePrimitiveExpression(entry.Expression.Trim().ToString());
      return new CodeMethodInvokeExpression(thisType, evaluationMethod, new CodeExpression[] { expression });
    }

    public static string GetResourceString(string key) {
      return @"\\\Output from custom ExpressionBuilder///";
    }
  }
}


Web.config
<?xml version="1.0"?>

<configuration>
  <appSettings/>
  <connectionStrings/>

  <system.web>
    <compilation debug="true" >
      <expressionBuilders>
        <add expressionPrefix="IHLPResource" type="IHLP2007PoC.Code.IHLPResourceExpressionBuilder"/>
      </expressionBuilders>
    </compilation>
    
    <authentication mode="Windows" />
    <pages />
    <globalization uiCulture="da" culture="da-DK" />
  </system.web>
</configuration>


Expected output
--------------------------------------------------------------------------------
1: Hi 
2: \\\Output from custom ExpressionBuilder/// 
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
1: Hi 
2: \\\Output from custom ExpressionBuilder///


Actual output
--------------------------------------------------------------------------------
1: Hi 
2: \\\Output from custom ExpressionBuilder/// 
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
1: Hi 
2: 


modified on Thursday, October 23, 2008 11:42 AM

AnswerRe: Custom ExpressionBuilder + ParseControl. No Joy? Pin
mgkr23-Oct-08 22:24
mgkr23-Oct-08 22:24 
Questionfor executing lnkAddTraveller_Command event block when click on lnkAddTraveller link always need 2 times click Pin
trilokharry23-Oct-08 4:01
trilokharry23-Oct-08 4:01 
QuestionQuery String! Pin
blakshmi23-Oct-08 2:31
blakshmi23-Oct-08 2:31 
AnswerRe: Query String! Pin
Brij23-Oct-08 3:41
mentorBrij23-Oct-08 3:41 
AnswerRe: Query String! Pin
Abhijit Jana23-Oct-08 3:42
professionalAbhijit Jana23-Oct-08 3:42 
QuestionCan it is possible to fetch Client Mechine IP under Run Prosxy Server Pin
Rajeesrivastava23-Oct-08 2:18
Rajeesrivastava23-Oct-08 2:18 
AnswerRe: Can it is possible to fetch Client Mechine IP under Run Prosxy Server Pin
Paddy Boyd23-Oct-08 2:19
Paddy Boyd23-Oct-08 2:19 
QuestionDates of current week Pin
raghvendrapanda23-Oct-08 1:36
raghvendrapanda23-Oct-08 1:36 
AnswerRe: Dates of current week Pin
Ashfield23-Oct-08 2:06
Ashfield23-Oct-08 2:06 
GeneralRe: Dates of current week Pin
Abhijit Jana23-Oct-08 3:39
professionalAbhijit Jana23-Oct-08 3:39 
GeneralRe: Dates of current week Pin
Ashfield23-Oct-08 9:32
Ashfield23-Oct-08 9:32 
QuestionHow to read gmail inbox attchment from .aspx page ????? Pin
subrat4all23-Oct-08 1:32
subrat4all23-Oct-08 1:32 
AnswerRe: How to read gmail inbox attchment from .aspx page ????? Pin
Abhijit Jana23-Oct-08 1:58
professionalAbhijit Jana23-Oct-08 1:58 
GeneralRe: How to read gmail inbox attchment from .aspx page ????? Pin
subrat4all23-Oct-08 2:11
subrat4all23-Oct-08 2:11 
AnswerRe: How to read gmail inbox attchment from .aspx page ????? Pin
Abhijit Jana23-Oct-08 3:33
professionalAbhijit Jana23-Oct-08 3:33 
GeneralRe: How to read gmail inbox attchment from .aspx page ????? Pin
subrat4all23-Oct-08 21:28
subrat4all23-Oct-08 21:28 
QuestionInformation passed from one page to another Pin
Kartik Rathi23-Oct-08 1:08
Kartik Rathi23-Oct-08 1:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.