3

I have ASP code like this:

<ext:Panel ID="pnlHelp" CtCls="help-panel" AnimCollapse="true"">
    <Content>
        <h1>some text</h1>
        <p>
            More text[...]
        </p>
    </Content>
</ext:Panel>

I would like to generate the <Content> tag dynamically using C#. I tried this, like with regular HTML tags:

<ext:Panel ID="pnlHelp" CtCls="help-panel" AnimCollapse="true"">
    <Content>
        <% Response.Write("<h1>some text</h1>"); %>                             
        <p>
            More text[...]
        </p>
    </Content>
</ext:Panel>

But the text ends up somewhere near the beginning of the page where I didn't intend it to go. How can I do this?

2 Answers 2

4

You output appears on the top of the page because your Response.Write() is being executed before page content is put to respose.

Why not just

<%="<h1>some text</h1>" %> 

You can create a method that will return a string and call it from your *.as?x file:

protected string GetMyCoolHtml()
{
    return "<h3>this is my text</h3>";
}

....

<%= GetMyCoolHtml() %>
Sign up to request clarification or add additional context in comments.

5 Comments

It worked for the static phrase. But then I put in <%= GetPhrase("some_text_key", "<h1>some text</h1>"); %> and I'm getting a " ) expected" error. Why's that?
check the signature of you method. you code works for me when methoв is decalared as protected string GetPhrase(string key, string h1Text) { return key + "<br />" + h1Text; }
Remove the ';'. When using <%= %> for displaying things, no ; is expected.
oh, sure +1 to @Abbas comment :)
Okay, this works. What's the name of this inline code tag so I can read more about it?
1

Add a literal control to your page and write whatever you want on server side.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.