문제

I have a label control where I modify the text server side before it gets rendered. The weird thing is, when I break at the line where I access the text value, the result is an empty string, but when the control is rendered to the page, the Text contents are there.

<asp:Label id="_tealiumScript" Runat="server" EnableViewState="False">
    abc
    <script language="javascript" type="text/javascript">
        var GetServerName = function() {
            var servername;
            try { servername = "<%=Server.MachineName %>"; } catch (e) { }
            return servername;
        }
    </script>
</asp:Label>

On top of that, when I take out the contents in the element, I can access the text; I can see "abc" as well as the opening and closing script tags. All this, and it works in other controls in the same platform.

This is where I try to access the text in a class called TrackingUserControl (which the code from the codebehind above inherits from):

protected override void OnLoad(EventArgs e)
    {
        string text = _tealiumScript != null ? _tealiumScript.Text : " not here either";


        base.OnLoad(e);
    }

Edit:

I tried taking different parts out, and what I found was when I have the text

"<%=Server.MachineName %>"

in there, I can't access the text property of the control. if I take it out, it's fine. If anyone can enlighten me on why this happens I will be more than grateful!

도움이 되었습니까?

해결책

I tried taking different parts out, and what I found was when I have the text

"<%=Server.MachineName %>"

in there, I can't access the text property of the control. if I take it out, it's fine.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top